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 ?
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 ?
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