Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise Invitable : Optionally Send Email

in devise invitable, you can invite a new user by performing:

User.invite!(:email => "[email protected]", :name => "John Doe")

What I would like to do is (sometimes) prevent devise invitable from sending out an email. I found the following code in the library:

def invite!
        if new_record? || invited?
          self.skip_confirmation! if self.new_record? && self.respond_to?(:skip_confirmation!)
          generate_invitation_token if self.invitation_token.nil?
          self.invitation_sent_at = Time.now.utc
          save(:validate => false)
          ::Devise.mailer.invitation_instructions(self).deliver
        end
      end

Any ideas on how to best update that to not send out the email on the last line? I'm not familiar with the ::

thanks

like image 394
AnApprentice Avatar asked Dec 17 '22 18:12

AnApprentice


1 Answers

you can use:

User.invite!(:email => "[email protected]", :name => "John Doe") do |u|
  u.skip_invitation = true
end

or

User.invite!(:email => "[email protected]", :name => "John Doe", :skip_invitation => true)

this will skip invitation email.

like image 100
Mateusz Avatar answered Dec 19 '22 06:12

Mateusz