我製成的購物車和各產品具有點擊時生成以下消息的刪除鏈接:滑軌刪除鏈接生成路由錯誤
路由錯誤沒有路由匹配[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