I am getting routing error No route matches [GET]
upon delete
request. Here is my delete route
delete '/remove/:product_id', to: 'carts#remove_product'
I am using it like this
<a href="/remove/<%=subq.product.id%>" method="delete"></a>
. Any idea about this error?
Asked
Active
Viewed 805 times
0

rubhan
- 34
- 6
-
3Is there any reason you are not using the `link_to` helper? Something like [this](https://stackoverflow.com/questions/1317448/how-to-create-a-delete-link-for-a-related-object-in-ruby-on-rails) may be what you are trying to do. – Justin Wood May 28 '16 at 15:03
-
Noting special. Just using a-tag because of styling reasons, because I have an i-tag inside my a-tag. It should not make any difference. right? – rubhan May 28 '16 at 15:29
1 Answers
3
As Justin Wood suggested, you could use Rails' link_to helper, which would look like this :
<%= link_to 'Destroy', your_method_path(subq.product), :method => :delete %>
If you want to stick to your current way of doing it, you could try (please note data-method
instead of method
, see https://stackoverflow.com/a/35283202/4480140):
<a href="/remove/<%=subq.product.id%>" data-method="delete"></a>
And also check that in your application.js file you have
//= require jquery
//= require jquery_ujs
And finally that application.js file is included into view/layout/application.html.erb
file. Cf https://stackoverflow.com/a/17748391/4480140

Community
- 1
- 1

Pholochtairze
- 1,836
- 1
- 14
- 18