[英]Rails Routing Error (undefined local variable or method `micropost_comment')
我不太清楚为什么在StaticPages#home中的NameError。 这是我来自
views/comments/_comment.html.erb
代码
<% if current_user?(comment.user) %>
<%= link_to 'Destroy', micropost_comment, method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>
这是我的路线
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
有人可以解释如何解决此错误
undefined local variable or method `micropost_comment'
先感谢您
link_to的第二个参数是路径
micropost_comment不是路径,应将其替换为micropost_comment_path
对于您的路线,还应添加以下参数:
<%= link_to 'Destroy', micropost_comment_path(micropost_id:comment.micropost_id, id:comment.id), method: :delete, data: { confirm: 'Are you sure?' } %>
我认为您虽然不需要嵌套路由,但这是另一个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.