Search code examples
ruby-on-railsdeviserubygems

Is there any way i can check if the user is not active since x months


I'm using rails 6 and devise for authentication. I know it can be done with session but dont know how. I will be thankful for your kind response.


Solution

  • If by active you mean that a user hasn't signed in for x months. Then you can check last_sign_in_at column in users table. The column should be created by Devise.

    months = 6 # Put your value here
    if user.last_sign_in_at? && user.current_sign_in_at.blank?
      user.last_sign_in_at < Time.now.months_ago(months)
    end
    

    If a user has never been signed in you can check created_at field in a similar way.