Receiving from user: request.referer does not work

When a user navigates to a page but is not logged in, he is redirected back to my login page.

def authenticate_user!
  redirect_to new_user_path unless current_user
end

Then in my user manager

class UsersController < ApplicationController
  skip_before_filter :authenticate_user!, only: [:new, :create]

  def new
    puts request.referer          #=> nil
    puts request.referrer         #=> nil
    puts request["HTTP_REFERER"]  #=> nil
    puts request["HTTP_REFERRER"] #=> nil
    ...
  end
end

I don’t get anything from variables referrerwhen I go to another page (but it redirects to /users/newcorrectly). Even with a direct transition to the page, /users/newI get nothing for any of these variables. How do I get the path from which they came? I saw examples using the code below, but referrershould not be nil

previous = Rails.application.routes.recognize_path(request.referer)
+4
source share

Source: https://habr.com/ru/post/1534921/


All Articles