Rails HTML/TEXT UserMailer Templates
Currently for my Rails 3 mailer templates, I need to create an html
and text
version in the vie开发者_Python百科ws/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?
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.
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:
- https://github.com/plataformatec/markerb
- https://github.com/Mange/roadie
- https://github.com/fphilipe/premailer-rails3
精彩评论