Rails HTML/TEXT UserMailer Templates

大城市里の小女人 提交于 2019-12-13 14:21:35

问题


Currently for my Rails 3 mailer templates, I need to create an html and text version in the views/user_mailer directory.

Why is that necessary? Why can't rails look at the html version and automatically format it to a text/plain version?


回答1:


This is not required. You can simply provide one of those templates. For instance, if you don't need HTML, you can create the TEXT file only.

Likewise, you can provide the HTML template only. Readers will attempts to extract the information. However, if you use HTML, you should provide an alternative TEXT version to make sure the readers won't mess the content of your email.

By the way, Rails doesn't force you to provide both templates.




回答2:


This question seems to be similar to yours and might be helpful to you:

Graceful degradation/progressive enhancement for Action Mailer templates?

Also, here are some direct links to some gems that help to solve this problem of duplication between html and text mailer templates:

  1. https://github.com/plataformatec/markerb
  2. https://github.com/Mange/roadie
  3. https://github.com/fphilipe/premailer-rails3


来源:https://stackoverflow.com/questions/4908446/rails-html-text-usermailer-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!