[英]Rails Routing Error (undefined local variable or method `micropost_comment')
NameError in StaticPages#home I don't quite understand why.
我不太清楚为什么在StaticPages#home中的NameError。 Here my code from
views/comments/_comment.html.erb
这是我来自
views/comments/_comment.html.erb
代码
<% if current_user?(comment.user) %>
<%= link_to 'Destroy', micropost_comment, method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>
Here's my routes 这是我的路线
micropost_comment GET /microposts/:micropost_id/comments/:id(.:format) comments#show
PATCH /microposts/:micropost_id/comments/:id(.:format) comments#update
PUT /microposts/:micropost_id/comments/:id(.:format) comments#update
DELETE /microposts/:micropost_id/comments/:id(.:format) comments#destroy
can some one explain how to fix this error 有人可以解释如何解决此错误
undefined local variable or method `micropost_comment'
thank you in advance 先感谢您
The second argument of link_to is a path link_to的第二个参数是路径
micropost_comment is not a path, you should replace it with micropost_comment_path micropost_comment不是路径,应将其替换为micropost_comment_path
also regarding to you routes, you should add those params : 对于您的路线,还应添加以下参数:
<%= link_to 'Destroy', micropost_comment_path(micropost_id:comment.micropost_id, id:comment.id), method: :delete, data: { confirm: 'Are you sure?' } %>
I think you don't need nesting routes though, but it's an other question 我认为您虽然不需要嵌套路由,但这是另一个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.