我认为您正在寻找资源而不是匹配...
resources :recipes do
resources :ingredients
end
给你:
recipe_ingredients GET /recipes/:recipe_id/ingredients(.:format) {:action=>"index", :controller=>"ingredients"}
recipe_ingredients ingredient /recipes/:recipe_id/ingredients(.:format) {:action=>"create", :controller=>"ingredients"}
new_recipe_ingredient GET /recipes/:recipe_id/ingredients/new(.:format) {:action=>"new", :controller=>"ingredients"}
edit_recipe_ingredient GET /recipes/:recipe_id/ingredients/:id/edit(.:format) {:action=>"edit", :controller=>"ingredients"}
recipe_ingredient GET /recipes/:recipe_id/ingredients/:id(.:format) {:action=>"show", :controller=>"ingredients"}
recipe_ingredient PUT /recipes/:recipe_id/ingredients/:id(.:format) {:action=>"update", :controller=>"ingredients"}
recipe_ingredient DELETE /recipes/:recipe_id/ingredients/:id(.:format) {:action=>"destroy", :controller=>"ingredients"}
recipes GET /recipes(.:format) {:action=>"index", :controller=>"recipes"}
recipes ingredient /recipes(.:format) {:action=>"create", :controller=>"recipes"}
new_recipe GET /recipes/new(.:format) {:action=>"new", :controller=>"recipes"}
edit_recipe GET /recipes/:id/edit(.:format) {:action=>"edit", :controller=>"recipes"}
recipe GET /recipes/:id(.:format) {:action=>"show", :controller=>"recipes"}
recipe PUT /recipes/:id(.:format) {:action=>"update", :controller=>"recipes"}
recipe DELETE /recipes/:id(.:format) {:action=>"destroy", :controller=>"recipes"}
因此您的编辑操作变为:
<%= link_to 'Edit Ingredient', edit_recipe_ingredient_path(@ingredient.recipe, @ingredient) %>
显示动作变成:
<%= link_to 'Edit Ingredient', [@ingredient.recipe, @ingredient] %>
否则,您将不得不执行以下操作:
<%= link_to 'Edit Ingredient', :controller => :ingredients, :action => :show, :id => @ingredient.id, :recipe_id => @ingredient.recipe %>