我正在使用 griddler 和 sendgrid 将电子邮件接收到我的 rails 应用程序中,但是当我渲染 email.body 时,我只得到电子邮件中的文本,而不是实际的 html 样式的电子邮件。我使用<%= raw post.body %>
并且仍然得到同样的东西。关于如何让电子邮件正文呈现其 html 版本的任何想法,就好像您会在 Gmail 或 Yahoo 中看到它一样,而不是将其剥离并仅呈现电子邮件中的文本。我正在使用 Rails 4、Sendgrid 和 Griddler Gem。
我的 email_processor.rb 文件来处理电子邮件:
class EmailProcessor
def self.process(email)
Post.create!({ body: email.body, email: email.from })
end
end
index.html.rb
<h1>Posts</h1>
<% if @posts.count > 0 %>
<% @posts.each do |post| %>
<blockquote>
<p><%= raw post.body %></p>
<small><%= post.email %></small>
</blockquote>
<% end %>
<% else %>
<p><em>Oops, doesn't look like there are any posts yet.</em></p>
<% end %>