Search code examples
ruby-on-railsregistrationdevise

How can I send a welcome email to newly registered users in Rails using Devise?


I am using Devise on Rails and I'm wondering if there is a hook or a filter that I can use to add a bit of code to Devise's user registration process and send a welcome email to the user after an account has been created. Without Devise it would be something like this...

  respond_to do |format|
      if @user.save
        Notifier.welcome_email(@user).deliver    # <======= 
  ...   

Solution

  • I solved this by using a callback method. It's not the cleanest of solutions, not as clean as an observer, but I'll take it. I'm lucky Mongoid implemented the ActiveRecord callbacks!

      after_create :send_welcome_mail
      def send_welcome_mail
         Contact.welcome_email(self.email, self.name).deliver
      end