Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7950935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:24:57+00:00 2026-06-04T02:24:57+00:00

After a successful login via Devise, how can I redirect the user back to

  • 0

After a successful login via Devise, how can I redirect the user back to the page they were on?

I’ve read and searched a lot already, and I understand that I need to define after_sign_in_path_for. I’ve done this and its working correctly, what I’m having trouble with is understanding how the previous page is stored, and how to call it correctly.

I have this in my sessions controller:

def after_sign_in_path_for(resource)
    return request.env['omniauth.origin'] || session[:user_return_to] || root_path
end

I’ve also tried

...
return request.env['omniauth.origin'] || stored_location_for(resource) || root_path
...

I don’t think I am understanding how to store the location, as the user is redirected back to the root path if they click to log in.

A sign in can be initiated in two ways. Either (a) the user attempts to access a restricted view (i.e. before_filter :authenticate_user!..., in which case they are redirected and prompted to login. Or (b) the user clicks a sign in link which is available on every page if the user is not logged in.

(a) seems to be working. (b) is not. I guess I need to store the current location to session when the user clicks the log in link.

How do I do this? Or, where is a good source of information that would help me understand this.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:24:58+00:00Added an answer on June 4, 2026 at 2:24 am

    You can get the previous url using request.referrer as is explained in this SO question: How to redirect to previous page in Ruby On Rails?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to redirect users to their associated 'home' page after successful login w/out nil'ing
A session is being passed after successful login from a aspx page to an
I have one application where after successful Login user will be redirected to Home.aspx.
In my JSF application ,after successful login, i am navigating to my home page
Currently after successful login I add md5($username) md5($password) in cookies and then every time
Im trying to test my successfully creates a new user after login (using authlogic).
After successful setup on initial launch of MySQL, the page prompted me to set
Shell (explorer.exe www.google.com) is how I'm currently opening my products ad page after successful
I'm using lightopenid as the login system for a site and after successful login,
I am trying to redirect users to the last page they logged in from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.