Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom message in devise invitable email

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
like image 744
CambridgeMike Avatar asked Nov 09 '11 01:11

CambridgeMike


2 Answers

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

like image 172
okliv Avatar answered Oct 22 '22 11:10

okliv


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>
like image 9
Nadeem Yasin Avatar answered Oct 22 '22 09:10

Nadeem Yasin