Rails: in Application Controller, force login, redirect all requests except login

I need a simple method in my application controller that requires all users to be logged in before going to any part of the site. I use Devise for authentication.

I tried:

class ApplicationController < ActionController::Base
  ...
  unless user_signed_in?
    redirect_to login_path
  end
  ...
end

This successfully redirects everyone, but the problem is that it also prevents mailing a request to create a new user session.

So my question is: how are you going to block all requests except the login and the send request?

+5
source share
1 answer

Devise . before_filter :authenticate_user! ApplicationController.

Devise - https://github.com/plataformatec/devise

, Rails 4.2+ before_action :authenticate_user!.

+9

All Articles