Permalink
Browse files

Better implementation of redirecting to stored URI - committed to nif…

…ty_generators plugin as well
  • Loading branch information...
1 parent 5872c15 commit 324027379c01e42944f0e19f0dca74292bed114f @bensie committed May 13, 2009
Showing with 10 additions and 9 deletions.
  1. +0 −5 app/controllers/application_controller.rb
  2. +1 −1 app/controllers/sessions_controller.rb
  3. +8 −3 lib/authentication.rb
  4. +1 −0 tmp/.gitignore
View
5 app/controllers/application_controller.rb
@@ -20,9 +20,4 @@ def admin?
end
helper_method :admin?
- def redirect_back_or_default(default)
- redirect_to(session[:return_to] || default)
- session[:return_to] = nil
- end
-
end
View
2 app/controllers/sessions_controller.rb
@@ -11,7 +11,7 @@ def create
subscriber = Subscriber.authenticate(params[:login], params[:password])
if subscriber
session[:subscriber_id] = subscriber.id
- redirect_back_or_default('/')
+ redirect_to_target_or_default(root_url)
else
flash.now[:warning] = "Invalid login or password."
render :action => 'new'
View
11 lib/authentication.rb
@@ -13,15 +13,20 @@ def logged_in?
def login_required
unless logged_in?
- flash[:notice] = "You need to login or create an account to continue."
- store_location
+ flash[:error] = "You must first log in or sign up before accessing this page."
+ store_target_location
redirect_to login_url
end
end
+ def redirect_to_target_or_default(default)
+ redirect_to(session[:return_to] || default)
+ session[:return_to] = nil
+ end
+
private
- def store_location
+ def store_target_location
session[:return_to] = request.request_uri
end
end
View
1 tmp/.gitignore
@@ -0,0 +1 @@
+restart.txt

0 comments on commit 3240273

Please sign in to comment.