Reputation: 171321
In index.html.erb
I display all products, and next to each product I have Edit
and Delete
actions:
<% @products.each do |product| %>
...
<%= link_to("Edit", edit_product_path(product.id), :class => 'action') %>
<%= link_to("Delete", product, :method => :delete, :class => 'action') %>
...
<% end %>
The Edit
link works ok. However, the Delete
link does not work. I get the following error:
Unknown action
The action 'show' could not be found for ProductsController
I guess it is because the request method is GET rather than DELETE. But, I don't know why this happens if I set explicitly :method => :delete
.
routes.rb
is pretty simple:
root :to => "products#index"
resources :products
I have Javascript enabled.
Please suggest.
Upvotes: 9
Views: 10949
Reputation: 41855
Dont forget to include jquery_ujs
in your application.js
file:
//
//= require jquery
//= require jquery_ujs
// ...
Upvotes: 5
Reputation: 1
I had same problem - actually I had changed my old 'delete' action to 'destroy' - but forgot If your using SSL.. (e.g ssl_required :destroy)
Upvotes: 0
Reputation: 107708
Do you have rails.js
specified in a javascript_include_tag
? This is required for the unobtrusive DELETE
method to work. If you're using jQuery then there's a solution for that too.
Upvotes: 13
Reputation: 51697
It needs to be product_path(product)
instead of product
in your delete link.
Upvotes: 2