如何将\'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\"
    

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...