I made a shopping cart and each product has a delete link that generates the following message when clicked:
Routing Error No route matches [GET] "/order_items/8"
The only change between the errors generated by each link is the order_item id.
The code is the following:
<%= 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" } %>
This is the generated link:
<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>
This is the relevant data in routes file:
resources :order_items, only: [:create, :update, :destroy]
When clicked, the alert pops up but the log shows this:
DELETE http://localhost:3000/order_items/11 422 (Unprocessable Entity)
What am I missing for the code to work.
//= require jquery_ujsand the gemjquery-railsis called on the Gemfile. I added the generated HTML in case something is wrong with it.