如何将'premailer'与Rails集成 [英] How to Integrate 'premailer' with Rails
本文介绍了如何将'premailer'与Rails集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将‘ premailer ’gem与Rails(3.0.7)项目集成在一起?我目前在邮件中:
How does one integrate the 'premailer' gem with a Rails (3.0.7) project? I currently have in my mailer:
def welcome(user)
@user = user
mail to: user.email, subject: "Welcome"
end
但是我无法弄清楚如何集成库。我需要致电:
But I can't figure out how to integrate the library. I need to call:
premailer = Premailer.new(html)
html = premailer.to_inline_css
但是,我不确定如何通过邮件操作访问电子邮件内容。
However, I'm not sure how to access the contents of my email from a mailer action.
推荐答案
尝试:
def premailer(message)
message.text_part.body = Premailer.new(message.text_part.body.to_s, with_html_string: true).to_plain_text
message.html_part.body = Premailer.new(message.html_part.body.to_s, with_html_string: true).to_inline_css
return message
end
def welcome(user)
@user = user
message = mail to: user.email, subject: "Welcome"
end
这篇关于如何将'premailer'与Rails集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文