没有路线匹配缺少必需的键:[:id] [英] No route matches missing required keys: [:id]
本文介绍了没有路线匹配缺少必需的键:[:id]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Rails的新手,看起来类似的问题,但我解决不了。
I'm new at Rails and I've seem similar problems, but I can't solve mine.
我的路线:
My routes:
resources :users do
resources :items
end
我的模特:
My models:
class Item < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :items
end
HTML:
<% @items.each do |item| %>
<tr>
<td><%= item.id %></td>
<td><%= item.code %></td>
<td><%= item.name %></td>
<td><%= item.quantity %></td>
<td><%= link_to "Edit", edit_user_item_path(item) %></td> <---- error
我得到了同样的错误:
And I'm getting the same error:
No route matches {:action=>"edit", :controller=>"items",
:user_id=>#<Item id: 1, user_id: 1, code: "123", name: "test",
quantity: 12, , created_at: "2014-02-11 15:45:30", updated_at:
"2014-02-11 15:45:30">, :id=>nil, :format=>nil} missing required keys: [:id]
推荐答案
用户以及它的嵌套路线。例如:
You need to include the user as well since its a nested route. So something like:
<td><%= link_to "Edit", edit_user_item_path(@user, item) %></td>
这篇关于没有路线匹配缺少必需的键:[:id]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文