我制成的购物车和各产品具有点击时生成以下消息的删除链接:滑轨删除链接生成路由错误
路由错误没有路由匹配[GET]“/ ORDER_ITEMS/8 “
每个链接产生的错误之间唯一的变化是order_item id。
的代码如下:
<%= link_to "Delete", order_item, { data: { confirm: "Are you sure you wish to delete the product '#{order_item.product.name}' from your cart?" }, method: :delete, remote: true, class: "btn btn-danger" } %>
这是所生成的链路:
<a data-confirm="Are you sure you wish to delete the product 'Name' from your cart?" class="btn btn-danger" data-remote="true" rel="nofollow" data-method="delete" href="/order_items/8">Delete</a>
这是路由文件中的相关数据:
resources :order_items, only: [:create, :update, :destroy]
单击时,该警报弹出,但日志显示:
DELETE http://localhost:3000/order_items/11 422(无法处理的实体)
缺少什么我的代码工作。
是否真的重定向或你忘了导入的jQuery -ujs(发送DELETE http动词) – siegy22
它正在从application.js中调用,如下所示:// = require jquery_ujs'并在Gemfile上调用gem'jquery-rails'。我添加了生成的HTML以防万一出错。 –
请添加您的日志。 – siegy22