Is there a way to include a redirect in a link_to? I want to just refresh the current page after a delete. But, you can delete the same record from multiple views in the app.
This is the link_to:
<%= link_to 'Delete', expense, confirm: 'Are you sure?', method: :delete, :class => 'btn btn-mini btn-danger' %>
If not, does it make sense to save the current_url in flash[:fromurl] then put that in the Controller destroy section like this:
respond_to do |format|
format.html { redirect_to flash[:fromurl] }
format.json { head :no_content }
end
Thanks for the help!
You can use the redirect_to :back
:
respond_to do |format|
format.html { redirect_to :back }
format.json { head :no_content }
end
It uses the header "HTTP_REFERER" from the request:
redirect_to :back
# is a shorthand for:
redirect_to request.env["HTTP_REFERER"]
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