Lets say I have a message resource. Somewhere in the html I have:
<%= link_to("Delete", message, :title => 'Delete', :confirm => 'Are you sure?',
:method => :delete )%>
Right after I delete it, it redirects me to the page where it lists all the messages. Is there a way to redirect to a page that I specify after the deletion?
In the controller:
def delete
Item.find(params[:id]).destroy
redirect_to :action => "index"
end
To redirect to the last url, use:
redirect_to :back
http://api.rubyonrails.org/classes/ActionController/Base.html#M000662
If you can learn how to read api docs well, they are extremely useful, once you get the hang of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With