Devise Sending Welcome Email

2019-05-31 18:00发布

问题:

I have a devise model called members i am using devise confirmable. Upon confirm i want to send a welcome email to the User

class Member < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :confirmable

  # Methods

  # Override devise confirm! message
  def confirm!
    welcome_email
    super
  end

  # Private Methods
  private

  def welcome_email
    MemberMailer.welcome_email(self).deliver
  end

end

My MemberMailer resides in mailers/brands/member_mailer.rb

class Brands::MemberMailer < ApplicationMailer

  # Send Welcome Email once Member confirms the account
  def welcome_email(member)
    @member = member
    mail(to: @member.email, subject: "Welcome to Skreem! Now you Rock!")
  end
end

But upon confirming through the mail Link the confirm! is not being overridden and I am not getting any error or email.

回答1:

Add this to your Member model:

def after_confirmation
  welcome_email
end

For more info check after_confirmation

@Pavan thanks for pointing this.

Your welcome_email should be:

def welcome_email
  Brands::MemberMailer.welcome_email(self).deliver
end