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 8778939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:39:10+00:00 2026-06-13T19:39:10+00:00

How do I redirect a user to a specific page when they login on

  • 0

How do I redirect a user to a specific page when they login on a particular form I create with Devise? There’s this howto page for Devise on how to redirect to a particular page after sign in. However, I want different forms to sign in to different target pages. Ideally, I can just add another HTML form parameter like this:

<input type="hidden" name="target" value="/dashboard"/>

UPDATE: It’s important that I maintain the normal functionality of Devise for a login page. That is, if I click on a link that has a before_filter :authenticate_user! in its controller, then I’ll be redirected to a login page. After logging in, then I’m redirected to the original destination page.

  • 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-13T19:39:11+00:00Added an answer on June 13, 2026 at 7:39 pm

    Actually you can simply define the after_sign_in_path_for method in your controller like that :

    class ApplicationController < ActionController::Base
    
      def after_sign_in_path_for
        params[:target] || some_default_url
      end
    
    end
    

    And then if your different sign in forms have different targets, then user should be properly redirected

    Adding

    <input type="hidden" name="target" value="/dashboard"/>
    

    to each particular form that would redirect to a specific page will then be enough 🙂

    EDIT : I think I finally understood what you exactly want. So here what I would do (based on this blogpost)

    class ApplicationController < ActionController::Base
      protect_from_forgery
    
      def after_sign_in_path_for(user)
        origin_path = session[:origin_path]
        clear_origin_path
        if origin_path.present?
          origin_path
        else
          params[:target].presence || default_redirect_path
        end
      end
    
      private
    
      def authenticate_user!
        store_origin_path
        super
      end
    
      def store_origin_path
        session[:origin_path] = request.fullpath
      end
    
      def clear_origin_path
        session[:origin_path] = nil
      end
    
    end
    

    So basically, if you try to access a protected path (let’s say /protected_resource), the path will be stored in the session, and then once user is logged in, the session will be cleared and user correctly redirected

    Then if a user goes on one of your different sign_in form and if that form contains a target input, then user will be redirected to that target.

    Finally, if user goes on a form without any target he’ll be redirected to a default_redirect_path that you might want to customize.

    Last thing : I assumed that the redirection to the original request was more important than the target so let’s say a user goes on /protected_resource and is therefore redirected to a sign_in form, even though this sign_in form has a target input, user will be redirected to /protected_resource after a successful sign in.

    You can easily change that by inverting the conditions in the after_sign_in_path_for method

    There might be a better way to do that, but this a starting point for you, and you might want to improve it 😉

    Let me know if my answer is not detailed enough.

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

Sidebar

Related Questions

What we need: redirect to each user's specific page after their login. What we
When I want to redirect a user to a specific page behind a login
I need to redirect any Authenticated user to a specific page if they do
I need to redirect a user to a different page if they visit a
Is there any way to redirect a page to a specific hash but prevent
I am trying to a redirect the user when they click on a specific
How to redirect the users to their id specific urls/landing pages after they log
I redirect the user to the home page after logout. In between I would
Is there a way to redirect the user to an error page (view) when
I've seen that it is possible to redirect users to a specific page after

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.