Let's say I have two models (Model1 and Model2) that share the same controller, both have many instances of Model3.
How can I achieve to nest Model 3 within both models and have the route: model_3_path(@model)
instead of model_1_model_3_path(@model)
and model_2_model_3_path(@model)
I want my model_3_path(@model)
function to look like this:
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
My current progress:
concern :three { resources :model3, shallow: true }
resources :model1, concerns: :three
resources :model2, concerns: :three, controller: :model1, except: [:index] # /model2 isn't permitted
I can't seem to find the right approach...