Ruby on Rails Devise code after login

后端 未结 3 1168
甜味超标
甜味超标 2020-12-16 01:32

I have an RoR app using Devise for logins. There is some code that is executed when a new User record is created, by being put in the user.rb file as an after_create call/m

3条回答
  •  感动是毒
    2020-12-16 01:59

    I think this is an duplicate question. Yes you can execute code after every successful log in. you could write the code in your ApplicationController. Also have a look at http://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in. Also, check out How to redirect to a specific page on successful sign up using rails devise gem? for some ideas.

    You can do something like:

    def after_sign_in_path_for(resource_or_scope)
    Your Code Here
    end
    

    Reference Can I execute custom actions after successful sign in with Devise?

    You could also inherit from devise session's class and use after_filter for logins.

提交回复
热议问题