0

同じコントローラーを共有する 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

私は正しいアプローチを見つけることができないようです...

4

2 に答える 2

-1

親を指定しないパスが必要な場合は、それを最上位ルートとして使用するだけで問題ありません。

于 2013-06-26T14:06:41.643 に答える