「レシピ」テーブルと「材料」テーブルがあります。各レシピ「has_and_belong_to_many」の材料と各材料「has_and_belong_to_many」のレシピ。
材料ページへのリンクを追加したい:「この材料を含むすべてのレシピを表示する」。
材料コントローラーに次のコードを記述しました。
def recipes
@ingredient = Ingredient.find(params[:id])
@recipes = @ingredient.recipes
respond_to do |format|
format.html # index.html.erb
format.json { render json: @recipes }
end
end
私の問題は、「成分」ビューの下に「recipes.html.erb」ファイルがあることを期待していることです。このために新しいビューを作成したくありません。「レシピ」ビュー(recipes / index.html.erb)で使用しているのと同じコードを使用したいだけです。レールをこのビューに誘導するにはどうすればよいですか?
(私はrails 3.xを使用しています)
ありがとう、李