I am using devise_invitable to invite users to app, for that I want to add custom message on the email. so my code looks like this.
#user.rb
attr_accessor :message
def self.invite(emails, message)
User.invite!({email: email}) do |user|
user.message = message
end
end
#here I am overriding devise_invitable method to send mails later
def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end
#users_controller.rb
def invite_user
User.invite(params[:email], params[:message])
end
#invitation_instructions.html.erb
<% if @resource.message %>
<p><%= @resource.message %></p>
<% end %>
When I am using only deliver then message is displaying on mailer, but when I use deliver_later attr_accessor in nil on the mailer view.
attr_accessor
doesn't work because deliver_later
serializes your User object to a GlobalID. When the delivery job runs, the job process wil re-load your user from the database (which of course does not include any instance variables on the object). You probably need to pass the message to the job (maybe you could sneak it into *args
, (hand
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With