Permalink
Browse files

Added ability to override the session key name.

Changed the default session key name to :comeback_to.
  • Loading branch information...
1 parent ae8e698 commit 9429c9bd6d936dbb7bc45fa699a1de48dc344cc1 @tylerhunt committed Sep 3, 2009
Showing with 15 additions and 6 deletions.
  1. +15 −6 lib/comeback.rb
View
@@ -1,19 +1,28 @@
module Comeback
- def clear_location
- session[:return_to] = nil
+ def self.included(base)
+ base.class_inheritable_accessor :comeback_session_key
+ base.comeback_session_key = :comeback_to
end
def store_location(url=nil)
- session[:return_to] ||= url ? url : request.url
+ session[comeback_session_key] ||= url ? url : request.url
end
def store_referer
referer = request.env['HTTP_REFERER']
- session[:return_to] ||= referer unless referer == request.url
+ store_location(referer) unless referer == request.url
+ end
+
+ def clear_location
+ session[comeback_session_key] = nil
end
def return_or_redirect_to(*args)
- session[:return_to] ? redirect_to(session[:return_to]) : redirect_to(*args)
- session[:return_to] = nil
+ if session[comeback_session_key]
+ redirect_to(session[comeback_session_key])
+ clear_location
+ else
+ redirect_to(*args)
+ end
end
end

0 comments on commit 9429c9b

Please sign in to comment.