For some reason I cannot find the documentation for this. How can I
store the current URI/URL so that I can return with a redirect_to?
session[last_action] = ???
For some reason I cannot find the documentation for this. How can I
store the current URI/URL so that I can return with a redirect_to?
session[last_action] = ???
Pulling some code from Rick O.'s acts_as_authenticated, roll
something akin to this following code. This requires that you’re using
sessions.
def redirect_back_or_default(default)
session[:return_to] ? redirect_to_url(session[:return_to]) :
redirect_to(default)
session[:return_to] = nil
end
Note, you’d want to put this in a file that’s accessible to your
controller or view. So application.rb or a global helper or in a lib
file called on load would be two good bets.
Taylor S. wrote:
For some reason I cannot find the documentation for this. How can I
store the current URI/URL so that I can return with a redirect_to?session[last_action] = ???
You might mean session[:last_action]= perhaps.
If you want to go back to the previous page, you can use redirect_to
:back.
I find it useful when POST validation fails and need to redisplay the
form.
I cannot use redirect_to :back because I need to refresh the page. In
either case presented, what is the rails method to get the current
action so that I can store it in the session?
Hmmm, I have used :back with good success so far. My form gets
refreshed. I wonder if this is a browser setting thing.
Anyway, try action_name within the action.
Long
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs