No route matches missing required keys: [:id]

隐身守侯 提交于 2019-12-02 16:34:15

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>
hainguyen

The problem is that you are using nested resources:

resources :users do
   resources :items
end

So when you have a link:

<%= link_to "Edit", edit_user_item_path(item) %> 

It will lack one user_id so the easy to check the issue is using rake routes. And it will list the routes like this:

edit_user_item GET    /users/:user_id/items/:id/edit(.:format) items#edit

You can see the routes above and check it with the link, you will see it does not have user_id. That's the main reason!

The object item is being passed instead of the required id.

<td><%= link_to "Edit", edit_user_item_path(item.id) %></td>

You've missed user_id in the following path:

edit_user_item_path(user_id, item)

format you are able to find just running bundle exec rake routes | grep edit_user_item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!