Search code examples
ruby-on-railsrubydeviseruby-on-rails-5

skip_before_filter for the "login" action of devise


I can do this to skip calling "authenticate_user" in a certain controller where I need to:

class ApplicationController
  before_filter :authenticate_user!
end

class MyController < ApplicationController
  skip_before_filter :authenticate_user!
end

I want to call skip_before_filter for "login" action of devise gem and I don't want to have to override anything else. How can I do that?


Solution

  • One approach is to override devise sessions controler:

    1) create a users/sessions_controller.rb file:

    class Users::SessionsController < Devise::SessionsController
       skip_before_filter :authenticate_user!
    end
    

    2) and set it on routes.rb:

    devise_for :users, controllers: { sessions: "users/sessions"}