【发布时间】:2010-02-10 02:43:36
【问题描述】:
我如何销毁关联本身并保留关联的对象,同时保持此 RESTful?
具体来说,我有这些模型:
class Event < ActiveRecord::Base
has_many :model_surveys, :as => :surveyable, :dependent => :destroy, :include => :survey
has_many :surveys, :through => :model_surveys
end
class ModelSurvey < ActiveRecord::Base
belongs_to :survey
belongs_to :surveyable, :polymorphic => true
end
class Survey < ActiveRecord::Base
has_many :model_surveys
end
也就是说,事件是:surveyable (ModelSurvey belongs_to Event)。我的问题是,无需创建ModelSurveysController,我如何销毁ModelSurvey,同时保留Event 和Survey?
map.resources :events, :has_many => :model_surveys 的东西?我不太确定在这种情况下该怎么做。路由需要做什么,控制器需要做什么?我希望网址看起来像这样:
/events/:title/model_surveys/:id
感谢您的帮助, 兰斯
【问题讨论】:
标签: ruby-on-rails rest polymorphic-associations destroy