如何解决如何将\'premailer\'与Rails集成
|| 如何将\'premailer \'gem与Rails(3.0.7)项目集成?我目前在邮件中:def welcome(user)
@user = user
mail to: user.email,subject: \"Welcome\"
end
但是我不知道如何集成该库。我需要致电:
premailer = Premailer.new(html)
html = premailer.to_inline_css
但是,我不确定如何通过邮件操作访问电子邮件的内容。
解决方法
尝试:
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 gem。它使用Rails邮件钩子进行转换。
,对于Rails 4用户,您可以:
添加宝石
gem \'premailer-rails\'
gem \'nokogiri\' (if you don\'t have it)
将此添加到您的样式表(Haml):
%style{type:\"text/css\"}= Rails.application.assets.find_asset(\'email_stylesheet\').to_s
由于某种原因,它无法使用正常的stylesheet_link_tag
那就是我要做的。希望对您有所帮助!
,要么
gem \"actionmailer_inline_css\"