Skip to content

Commit

Permalink
After the user is successfully logged in, redirect back to the last r…
Browse files Browse the repository at this point in the history
…equest url.
  • Loading branch information
manxingxing committed Sep 1, 2014
1 parent 60cb368 commit 04b4f61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def access_denied
redirect_back_or_default root_url
else
flash[:error] = 'Access denied. Try to log in first.'
session[:return_to] = request.url if request.get?
redirect_back_or_default root_url
end
end
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/user_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Login successful!"
redirect_back_or_default root_url
if session[:return_to]
redirect_to session[:return_to]
session.delete :return_to
else
redirect_back_or_default root_url
end
else
flash[:error] = @user_session.errors.full_messages.to_sentence
redirect_back_or_default root_url
Expand Down

0 comments on commit 04b4f61

Please sign in to comment.