public
Description: A Rails plugin that provides a mechanism for storing URLs to return to at a later time.
Homepage:
Clone URL: git://github.com/tylerhunt/comeback.git
tylerhunt (author)
Thu Sep 03 09:32:22 -0700 2009
commit  048cc8020be602782af8e9da2b624e41fda5e0b5
tree    352842affc8df8eafb5f18d0bdf69d2fece4123b
parent  96b429eca2808a23c5d2be9cd2f75ee7a3cc5670
README.markdown

Comeback

Provides a mechanism for storing URLs to return to at a later time. Allows the current URL, a custom URL, or the referer to be stored.

When a referer is stored, it is checked against the current page URL, and if they're the same, then the referer won't be set and the default path will be used instead.

By default, the session key :comeback_to is used to store the URL. The class inheritable accessor comeback_session_key can be set to override this.

Example

In your controller, you first call #store_referer to save the referer to the current page, and then to access it again, call #return_or_redirect_to and pass it the same arguments you would pass to #redirect_to as the default in case a referer has not been set:

class MyController < ApplicationController

def first_action
  store_referer
end

def second_action
  return_or_redirect_to root_path
end

end

You can also store the referer using a before filter:

class MyController < ApplicationController

before_filter :store_referer, :only => :first_action

def first_action
end

end

The current page URL can also be stored instead of the referer:

class MyController < ApplicationController

def first_action
  store_location
  redirect_to login_path
end

end

Explicit URLs may also be stored:

class MyController < ApplicationController

def first_action
  store_location dashbaord_path
  redirect_to login_path
end

end

Copyright (c) 2008 Tyler Hunt, released under the MIT license