Attractiveness: optional Send a letter

In the invitable application, you can invite a new user by doing:

User.invite!(:email => " new_user@example.com ", :name => "John Doe") 

What I would like to do is (sometimes) prevent unwanted email from being sent. 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 best to update so as not to send email on the last line? I am not familiar with ::

thanks

+4
source share
1 answer

you can use:

 User.invite!(:email => " new_user@example.com ", :name => "John Doe") do |u| u.skip_invitation = true end 

or

 User.invite!(:email => " new_user@example.com ", :name => "John Doe", :skip_invitation => true) 

this will skip the invitation email address.

+12
source

Source: https://habr.com/ru/post/1334289/


All Articles