Reputation: 4622
How do you pass a custom message to the devise invitable email? I want the inviter to include a message to the invitee, like "Hey check out this site".
I tried both including it in the attributes and setting an instance variable in the block, neither seem to be accessible from the email.
user = User.invite!(:email => share.to_user_email, :message => "hey check this out") do
@message = "hey it's me!"
end
Upvotes: 6
Views: 4682
Reputation: 4524
Email template will allow you to send same message for all the emails.
Here is another way/case, when you are taking message as an input from 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>
Upvotes: 8
Reputation: 2740
the content of the mail is in app/views/devise/mailer/invitation_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>
modify this file to customize.
Upvotes: 4
Reputation: 3959
you have to do rails generate devise_invitable:views users
then you will get new erb file app/views/users/mailer/invitation_instructions.html.erb
which you will be able to customize in any way you want
Upvotes: 12