I want to have a “Delete”-link on a page viewing an object in my Ruby on Rails project. I am running into problems as
<%= link_to "Delete", @member, :confirm => 'Are you sure?', :method => :delete %>
loads the page it is on, when the method has run, thus trying to load a non-existent object. I would like to return to an index page, once the object is deleted.
Any ideas?
The problem lies in your controller.
Make sure that the destroy action redirects to index and you should be fine.
If you used scaffolding to generate your controllers, this should already be done for you.
Example: