Rails HTML/TEXT UserMailer Templates - ruby-on-rails

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?

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

Related

In Ruby on Rails is there a way to put the path of every partial in an HTML comment?

I work on apps that often have thousands of partials and finding what partial is rendering a section of HTML can be tedious and just waste time.
In development mode, it would sometimes be very helpful to turn on a config to have every partial used be prefaced with its path in an HTML comment so I could quickly know how to access and edit it.
Is there a config option for this or a gem that someone has made for this?
This functionality is built-in to recent rails versions for erb templates.
See here for details: https://blog.saeloun.com/2020/05/11/rails-support-annotates-html-output-with-template-file-names.html
That page mentions another option you could try.
Here is a link to the rails pr that introduced the change: https://github.com/rails/rails/pull/38848

How to change common styles for redmine email messages?

I need to make some styles available for every html email message in my custom redmine plugin. So I should do something with mailer layout https://github.com/redmine/redmine/blob/master/app/views/layouts/mailer.html.erb
As this file doesn't contain any hook ( http://www.redmine.org/projects/redmine/wiki/Plugin_Tutorial#Using-hooks ) only thing I can imagine to do it in this case is to override the layout in the plugin.
Is there any way to avoid overriding?
There is a gem deface which can help you.
I changed some parts of the view on the fly using deface. Please see this commit.

Rails 3.2+ best practice for using Haml to generate Javascript templates (JST)

I asked a specific question about problems I'm having with a specific gem intended to do this in a separate thread ( https://stackoverflow.com/q/18577033/1206117?sem=2 )
But I feel I may be on the "wrong boat" somehow because all of the questions I find about Rails/Haml/JST-templates are at least 2 years old, or go unanswered.
I'm writing an app with a lot of client-side JS and so want to use templates to render views (I'm using Backbone). I want to use Haml to write the templates.
I'm not looking for a debate about which gem/method is better, I'm looking for A WAY that works and has current support and active use. At present I cannot write my JS templates in Haml, and it's a bummer. I'm avoiding CoffeeScript at present since I'm still rather new to Javascript.
I've submitted an issue to the haml git repo.
https://github.com/haml/haml/issues/716
Looks like https://github.com/netzpirat/haml_coffee_assets gives you what you want. (window.JST templates, written in HAML, with inline coffescript support)

Sharing colors between SASS files and Rails erb templates

I'm working on an email newsletter using ActionMailer that's associated to our Rails 3.0.7 application. So against all my instincts, I'm using inline styles like mad since that seems to be the only way to do things in html email. I'd also like to keep the color scheme consistent with the website in a DRY fashion.
Is there any way to share SASS color variables between a Rails application and its SCSS files for use in inline styling?
The only way I'm aware you can do this is to add .erb onto your sass files so that they're processed by Rails, then you can use application level constants:
<%= APP_CONFIG[:yourkey] %>
Similar question / more reading
Coding emails is such a heinous task that I try to turn off all the higher thinking regions of my brain that worry about good programming principles every time I have to do it. Unless email is the central part of this project I'd resist letting the constraints there affect the rest of your application design.
Best solution I've found so far is the premailer gem: https://github.com/alexdunae/premailer/
Post-processing your HTML with premailer inlines all the CSS defined in a separate stylesheet, letting you specify whatever you want in a SASS or CSS file.

Writing templates without using html for ruby on rails/django

I hate to explicitly use html/css to build pages. Is there a template language I can use to semantically and quickly describe the layout and content of the page so that later I can generate html and css from it?
I'm planning to use this on a django site (but I guess if such solution already exists for RoR I can always adapt it).
Thanks.
There's GRHML, which is HAML for Genshi. (Django adapter)

Resources