[英]ruby on rails: no routes using edit_path?
I have two different controllers I got from rails generate, and each controller has index, edit, update, destroy, etc... 我从Rails生成了两个不同的控制器,每个控制器都有索引,编辑,更新,销毁等。
Now I'm trying to relate these two controllers (lists and ideas). 现在,我试图将这两个控制器(列表和想法)联系起来。 I have this loop in my lists -> show page
我的清单中有这个循环->显示页面
<% @list.ideas.each do |idea| %>
<div>
<div class="list_idea_desc"><%= idea.description %></div>
<div><%= link_to 'Show', idea %></div>
<div><%= link_to 'Edit', edit_idea_path(idea) %></div>
<div><%= link_to 'Destroy', idea, method: :delete, data: { confirm: 'Are you sure?' } %></div>
</div>
<% end %>
I'm trying to get the edit_idea_path
to work, but it gives me error 我正在尝试使
edit_idea_path
工作,但是它给了我错误
No route matches {:action=>"edit", :controller=>"ideas",
:id=>#<Idea id: nil, name: nil, description: nil, picture: nil,
created_at: nil, updated_at: nil, list_id: 2>}
Any idea how I can use the two different controllers? 知道如何使用两个不同的控制器吗? Does this give enough information?
这是否提供足够的信息?
Thanks 谢谢
Your Idea
instance doesn't have an ID ( :id=>#<Idea id: nil...
), so the router can't generate a route for it. 您的
Idea
实例没有ID( :id=>#<Idea id: nil...
),因此路由器无法为其生成路由。 Make sure your Ideas are saved before attempting to generate yours for them. 在尝试为您的想法生成想法之前,请确保已保存它们。
Also, not directly related to the problem, but you can just use link_to "Edit", [:edit, idea]
to have it infer the route based on the class of idea
. 另外,与问题没有直接关系,但是您可以只使用
link_to "Edit", [:edit, idea]
来根据idea
类来推断路线。
check your routes.rb file as you are using RESTful routing 在使用RESTful路由时检查您的routes.rb文件
and if not help, paste the routes code here 如果没有帮助,请在此处粘贴路线代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.