JoHksi JoHksi - 6 months ago 13
Ruby Question

Accessing newly singed up user in Rails app using devise

I am currently making Rails app using devise.
After a new user signs up, I need to access newly singed up user's information to run my customized function.
However it seems like devise's

current_user
is nil since the user is not logged in yet until the user confirms the email.

I essentially just need to check whether user's
confirmed_at
is nil.

Is there a way to do this?

Answer

I would do this in the User model with a callback:

# in app/model/user.rb (assuming you have a User model)
after_create :run_customized_function

private
  def run_customized_function
    # whatever need to be done with this user, for example: 
    # Rails.logger.info("User##{id} just signed up with email '#{email}'")
  end