Skip to content

Welcome mailers

nrhammond edited this page · 1 revision

Welcome emails are really simple to implement in Clearance, although not completely obvious at first.

The proper place to trigger a welcome email would be somewhere when the user’s account is confirmed. Within Clearance this is done within the ConfirmationsController in the create action. If you take a look at app/controllers/clearance/confirmations_controller.rb#create you can see a great place to hook into, the @user.confirm_email! line.

def create
    @user = ::User.find_by_id_and_confirmation_token(
                   params[:user_id], params[:token])


First, create the mailer that will send out the welcome email.

script/generate mailer notifier welcome

You’ll probably want to add in a param to the email for the user object so that you can greet your user by name and use other pieces of information from their account. Edit your notifier model in app/models/notifier.rb.

def welcome(user, sent_at =
  subject    'Welcome!'
  from       ''
  sent_on    sent_at

  body       :user => user

Now, go over to your application’s user model, most likely app/models/user.rb and add in the confirm_email! method.

def confirm_email!

We call super here just in case that method is ever implemented within Clearance, it will go up the chain and call the parent method.

All done.

Something went wrong with that request. Please try again.