Stu*_*ssa 10 ruby ruby-on-rails actionmailer premailer
如何将' premailer'gem与Rails(3.0.7)项目集成?我目前在我的邮件中:
def welcome(user)
@user = user
mail to: user.email, subject: "Welcome"
end
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何整合图书馆.我需要打电话:
premailer = Premailer.new(html)
html = premailer.to_inline_css
Run Code Online (Sandbox Code Playgroud)
但是,我不确定如何从邮件程序操作访问我的电子邮件的内容.
尝试:
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
Run Code Online (Sandbox Code Playgroud)
对于Rails 4用户,您可以:添加宝石
gem 'premailer-rails'
gem 'nokogiri' (if you don't have it)
Run Code Online (Sandbox Code Playgroud)
将其添加到样式表(Haml):
%style{type:"text/css"}= Rails.application.assets.find_asset('email_stylesheet').to_s
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它无法使用正常的stylesheet_link_tag
这就是我必须做的一切.希望这有帮助!
| 归档时间: |
|
| 查看次数: |
4528 次 |
| 最近记录: |