如何销毁关联本身并让对象单独关联,同时保持这个 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
and ?Survey
有什么 map.resources :events, :has_many => :model_surveys
?我不太确定在这种情况下该怎么做。路由需要做什么,控制器需要做什么?我希望网址看起来像这样:
/events/:title/model_surveys/:id
谢谢你的帮助,兰斯