Custom Inventive Message

How do you pass a custom message to a development email address? I want the invitation to contain a message to the invitee, for example, "Hey, check this site."

I tried both to include it in the attributes and set the instance variable in the block, and none of them are accessible from email.

user = User.invite!(:email => share.to_user_email, :message => "hey check this out") do @message = "hey it me!" end 
+6
source share
3 answers

you need to do rails generate devise_invitable:views users

then you will get a new erb file app/views/users/mailer/invitation_instructions.html.erb , which you can configure in any way you want

+11
source

An email template allows you to send the same message for all emails.

Here is another way / case when you accept the message as input from the user.

model / user.rb

 attr_accessor :message 

controller

  User.invite!({email: email}, current_user) do |user| user.message = params[:message] end 

/views/devise/mailer/invitation_instructions.html.erb

 <p>Hello <%= @resource.email %>!</p> <p><%= @resource.message%>.</p> 
+6
source

the contents of the mail are in the app / views / devize / mailer / invite _instructions.html.erb. By default it is:

 <p>Hello <%= @resource.email %>!</p> <p>Someone has invited you to <%= root_url %>, you can accept it through the link below.</p> <p><%= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) %></p> <p>If you don't want to accept the invitation, please ignore this email.<br /> Your account won't be created until you access the link above and set your password.</p> 

edit this file for customization.

+4
source

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


All Articles