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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:53:44+00:00 2026-06-03T07:53:44+00:00

With devise one uses before_filter :authenticate_user! to restrict access to authenticated users only. When

  • 0

With devise one uses before_filter :authenticate_user! to restrict access to authenticated users only.

When an unauthenticated user tries to visit a restricted page anyways, devise automatically causes a redirect to the sign in page.

So trying to open http://localhost:3000/users/edit will result in a redirect to http://localhost:3000/users/sign_in.

Now, if I define the link http://localhost:3000/users/edit as :remote => true, devise will only issue a 401 status code via JS.

How can I elegantly cope with that situation and display the login dialog in an overlay OR redirect as the non-remote variant would do it?

Does devise offer a default strategy for that situation which I’d simply need to activate?

  • 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-03T07:53:45+00:00Added an answer on June 3, 2026 at 7:53 am

    This is the solution I chose for now (in CoffeeScript syntax):

    $ ->
      $("a").bind "ajax:error", (event, jqXHR, ajaxSettings, thrownError) ->
        if jqXHR.status == 401 # thrownError is 'Unauthorized'
          window.location.replace('/users/sign_in')
    

    However this (on it’s own) just forgets about the page the user wanted to visit initially, which confines usability.

    Additional (controller) logic is required for more elegant handling.

    UPDATE: correct redirect

    Within the function, this holds the initial URL the user intended to go to.

    By calling window.location.replace(this) (instead of explicitly redirecting to the sign in page), the app will try to redirect the user to the initially intended destination.

    Although still impossible (unauthorized), this will now be a GET call (instead of JS/AJAX). Therefore Devise is able to kick in and redirect the user to the sign in page.

    From there on, Devise operates as usual, forwarding the user to the originally intended URL after successful sign in.

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

Sidebar

Related Questions

So suppose 1 Gemfile uses devise 1.0 and another one also requires that same
I have a Rails site that uses Devise for authentication. I have one page
One of my users is reporting a crash on his device, an iPhone 3GS.
I currently have an app that uses regular Devise authentication for logging in and
Seemingly, no one uses assembly nowadays other than to develop device drivers, or the
Our application (sadly) uses an MDB back-end database (I.e. JET engine). One of the
I've got a rails 3 production app that uses devise to deal with authentication.
I have a users model with Devise, and I've set up roles so users
In one of projects I have a file written in ARM assembly that uses
I’m making an android app, which uses Google maps. One functionality is that the

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.