同じコントローラーを共有する 2 つのモデル (Model1 と Model2) があり、両方とも Model3 のインスタンスが多数あるとします。
両方のモデル内にモデル 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
私は正しいアプローチを見つけることができないようです...