如何在邮件方法的邮件布局中包含条件?

Nic*_*ick 2 ruby ruby-on-rails ruby-on-rails-4

我正在 Rails 中设计邮件程序布局。这是不同邮寄者将使用的一般布局。在总体布局的中间,我想包含一个链接,但前提是它user_mailer.rbdef account_activation(user)发送电子邮件的方法一起使用。有没有办法做到这一点?

在我尝试的布局中:

<% if mailer_name == 'user' && ['account_activation'].include?(action_name) %>
Run Code Online (Sandbox Code Playgroud)

但这产生了错误:

undefined local variable or method 'mailer_name' for #<#<Class:0x007f18d0701f30>:0x00000006109c70>
Run Code Online (Sandbox Code Playgroud)

如果我改变mailer_name,以mailer使其不再产生一个错误,但它并没有显示链接是(尽管我期待在预览的ACCOUNT_ACTIVATION方法。

Phi*_*rom 5

在您的布局中,在页脚部分放置如下内容:

<div id='footer'>
  copyright | terms | privacy
  <% if content_for?(:footer) %>
    |
    <%= yield :footer %>
  <% end %>
</div>
Run Code Online (Sandbox Code Playgroud)

然后在您的特定邮件视图中执行以下操作:

<% content_for :footer do %>
  special link
<% end %>
Run Code Online (Sandbox Code Playgroud)

我这样做是为了在电子邮件的页脚中添加特殊注释,这些注释因电子邮件而异。效果很好。