【发布时间】:2013-06-26 13:57:21
【问题描述】:
假设我有两个模型(Model1 和 Model2)共享同一个控制器,它们都有很多 Model3 实例。
如何实现在两个模型中嵌套 Model 3 并拥有路径:model_3_path(@model) 而不是 model_1_model_3_path(@model) 和 model_2_model_3_path(@model)
我希望我的 model_3_path(@model) 函数看起来像这样:
def model_3_path(model)
if model.is_a? Model1
"/model1/#{model.id}/model3"
elsif model.is_a? Model2
"/model2/#{model.id}/model3"
end
end
我目前的进度:
concern :three { resources :model3, shallow: true }
resources :model1, concerns: :three
resources :model2, concerns: :three, controller: :model1, except: [:index] # /model2 isn't permitted
我似乎找不到正确的方法...
【问题讨论】:
标签: ruby-on-rails custom-routes nested-routes