如何将'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但是,我不确定如何从邮件程序操作中访问我的电子邮件内容。
发布于 2011-05-27 10:17:05
尝试:
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发布于 2011-06-01 01:14:28
看看我最近写的简单的premailer-rails gem。它使用Rails邮件钩子进行转换。
发布于 2014-08-16 07:28:47
对于Rails4用户,您可以:添加gem
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一起工作
这就是我要做的一切。希望这对你有所帮助!
https://stackoverflow.com/questions/6127068
复制相似问题