如何将自定义消息传递给设计可信的电子邮件?我希望邀请者向被邀请者添加一条消息,例如“嘿,看看这个网站”。
我尝试将它包含在属性中并在块中设置实例变量,似乎都无法从电子邮件中访问。
user = User.invite!(:email => share.to_user_email, :message => "hey check this out") do
@message = "hey it's me!"
end
答案 0 :(得分:11)
你必须做rails generate devise_invitable:views users
然后您将获得新的erb文件app/views/users/mailer/invitation_instructions.html.erb
,您可以以任何方式自定义
答案 1 :(得分:8)
电子邮件模板将允许您为所有电子邮件发送相同的消息。
当您将消息作为用户的输入时,这是另一种方式/案例。
模型/ user.rb
attr_accessor :message
控制器
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>
答案 2 :(得分:4)
邮件内容位于app / views / devise / mailer / invitation_instructions.html.erb中。默认情况下是:
<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>
修改此文件以进行自定义。