ActionMailer渲染更多,然后需要

时间:2015-12-09 17:16:23

标签: ruby-on-rails actionmailer

类UserMailer

def notification_email(user, msg_body, msg_count)
    @user = user
    @msg_body = msg_body
    mail(to: @user.email, subject: "New comments. #{msg_count}.")
  end

notification_email.html.erb

<!DOCTYPE html>
<html>
<head>
  <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>You have new comments </h1>
<p>
  <ul>
   <%= @msg_body.each do |msg| %>
    <li><a href="<%= msg %>"><%= msg %></a></li>
   <% end %>
  </ul>
</p>
</body>
</html>

对于消息体,我传递给视图数组 msg_body 。在 mailcatcher 中,我可以看到我需要的href列表。但我也在列表后面看到数组为纯文本。我真的无法理解它的去向。

1 个答案:

答案 0 :(得分:1)

尝试将<%= @msg_body.each do |msg| %>更改为<% @msg_body.each do |msg| %> - 从每个块中移除相等