Reputation: 839
I'm working on a project using ruby on rails. I want to refresh the same page when the action is called or redirect to the page where the action is called.
How do i do this ?
Upvotes: 1
Views: 9360
Reputation: 2054
Rails has a redirect_to :back
. More information here: http://api.rubyonrails.org/classes/ActionController/Redirecting.html
As noted, it is equivalent to redirect_to(request.env["HTTP_REFERER"])
which is "set me back to the page that sent me here."
You could make a controller action that does what you want then redirect_to :back
at the end.
Upvotes: 0
Reputation: 1308
you can use 'render' to refresh a page, and 'redirect_to' to redirect to a page going through its controller.
if you want to store a page to redirect back to, you can use:
def store_location
session[:return_to] = request.fullpath
end
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
clear_return_to
end
def clear_return_to
session[:return_to] = nil
end
This is taken from Michael Hartl's book, he uses similar code to redirect to the requested page after the user signs in.
http://railstutorial.org/chapters/updating-showing-and-deleting-users#sec:friendly_forwarding
Upvotes: 4