Using mail_to with a block (mail_to … do)

2019-07-04 16:06发布

问题:

I would like to do the following to insert a styled mail_to:

<%= mail_to @colleague.email do %>
  <span class="email" id="colleague_40"> Reply by Email </span>
<% end %>

The RoR docs aren't specific on the topic of mail_to blocks but the above code doesn't seem to work. Is there a way to do a block in conjunction with mail_to?

回答1:

<% mail_content = capture do %>
    <span class="email" id="colleague_40"> Reply by Email </span>
<% end %>

<%= mail_to @colleague.email, mail_content %>