“没有路线匹配..”尝试从购物车删除商品时出错
我有一个产品购物车(称为“line_items”),我正在尝试添加一个按钮来减少购物车中的商品数量:
3x Coke $2.97 (-)
这是“(-)”部分的代码:
<%= button_to '(-)', line_item, :confirm => 'Are you sure?',
:method => :destroy, :product_id => line_item.product_id %>
我的 line_item.destroy 函数很简单,只是减少数量,然后重定向回主页。在测试中,当我尝试单击按钮时,出现此错误:
ActionController::RoutingError (No route matches "/line_items/61")
看来系统正在尝试访问 line_item 的 URL,而不是像我想象的那样遵循我在控制器中设置的销毁函数会的。有什么想法如何解决这个问题吗?
I have a shopping cart of products (called "line_items"), and I'm trying to add a button to decrease the amount of something from the cart:
3x Coke $2.97 (-)
Here's the code for the "(-)" portion:
<%= button_to '(-)', line_item, :confirm => 'Are you sure?',
:method => :destroy, :product_id => line_item.product_id %>
My line_item.destroy function is pretty simple, it just decrements the quantity and then redirects back to the homepage. In testing, when I try to click the button, I get this error:
ActionController::RoutingError (No route matches "/line_items/61")
So it appears that the system is trying to visit the URL for the line_item, instead of following the destroy function I've set up in the controller it like I thought it would. Any ideas how to fix that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
:method
是 HTTP 动词,应该是:delete
而不是:destroy
:method
is the HTTP verb and it should be:delete
and not:destroy