Rails - How to override devise SessionsController to perform specific tasks when user signs in?

后端 未结 3 1232
囚心锁ツ
囚心锁ツ 2020-12-02 22:39

Using Devise to manage users sessions / registrations I would need to perform specific tasks (updating some fields in the users table for this specific user for example) eac

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 23:02

    Devise provides after_database_authentication callback method.You have full access for the current authenticated user object over there.

    If you want to update current user name after every successful login you can do that like below.

    class User < ActiveRecord::Base
      devise :database_authenticatable
    
      def after_database_authentication
        self.update_attributes(:name => "your name goes here")
      end 
    end
    

提交回复
热议问题