我在我的 routes.rb 中有这样的嵌套资源-(我的 rake:routes gist)
namespace(:admin) do
resources :restaurants do
resources :menus
resources :menu_items
end
end
在控制器中:
def new
@restaurant = Restaurant.find(params[:restaurant_id])
@menu_item = @restaurant.menu_items.build
end
尝试通过 url 创建一个新的 MenuItem(操作 #new):http: //127.0.0.1 :3001/admin/restaurants/1/menu_items/new我收到错误:
NoMethodError in Admin/menu_items#new
Showing /home/fps/workspace3/peded/app/views/admin/menu_items/_form.html.erb where line #1 raised:
undefined method `admin_menu_items_path' for #<#<Class:0xb6582d78>:0xb6581f2c>
Extracted source (around line #1):
1: <%= form_for @menu_item do |f| %>
...
我如何使这个表格工作?它是由一个漂亮的:脚手架创建的
更新
我也在_form中试过这个:
<%= form_for [:restaurant, @menu_item] do |f| %>
但以类似的错误结束:
Showing /home/fps/workspace3/peded/app/views/admin/menu_items/_form.html.erb where line #1 raised:
undefined method `restaurant_admin_menu_items_path' for #<#<Class:0xb68162b0>:0xb6813dd0>
Extracted source (around line #1):
1: <%= form_for [:restaurant, @menu_item] do |f| %
我应该提交错误吗?