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] = ???
on 2006-12-27 05:02
on 2006-12-27 05:09
Pulling some code from Rick Olson'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
on 2006-12-27 05:11
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.
on 2006-12-27 05:15
Taylor Strait 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. Long http://edgesoft.ca/blog/read/2
on 2006-12-27 05:21
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?
on 2006-12-27 06:11
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