DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Redirect Back To A Previous Action

01.04.2006
| 8408 views |
  • submit to reddit
        I am pasting this verbatim from LoginSystem

# move to the last store_location call or to the passed default one
  def redirect_back_or_default(default)
    if @session[:return_to].nil?
      redirect_to default
    else
      redirect_to_url @session[:return_to]
      @session[:return_to] = nil
    end
  end

In your controller...

 redirect_back_or_default :controller => "myfuel", :action => "index"