Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify a stylesheet for my HTML email with Premailer-Rails gem?

I have a stylesheet I want to use in my HTML emails at the path: app/vendor/assets/stylesheets/inspinia/email_templates/email-styles.css

I am using the Premailer-Rails gem for my email styling.

In my mailer.html.erb layout, I have the following:

<%= stylesheet_link_tag "inspinia/email_templates/email-styles.css", media: 'all' %>

However, in my logs on Heroku, I get the following message:

app[web.1]: [923202d9-b3f1-4b9a-9f42-7b70dcc01d92] Started GET "/stylesheets/inspinia/email_templates/email-styles.css" for 54.167.56.21 at 2016-12-23 23:25:08 +0000
app[web.1]: [923202d9-b3f1-4b9a-9f42-7b70dcc01d92]   
2016-12-23T23:25:08.286725+00:00 app[web.1]: [923202d9-b3f1-4b9a-9f42-7b70dcc01d92] ActionController::RoutingError (No route matches [GET] "/stylesheets/inspinia/email_templates/email-styles.css"):

So how do I figure out/specify the correct path for this stylesheet in production?

like image 397
marcamillion Avatar asked Dec 23 '16 23:12

marcamillion


1 Answers

try move email-styles.css to /public/assets/ folder, or add it to the assets pipeline. Premailer-rails wiki:

  1. File System: If there's a file inside public/ with the same path as in the URL, it is read from disk. E.g. if the URL is http://cdn.example.com/assets/email.css the contents of the file located at public/assets/email.css gets returned if it exists.

  2. Asset Pipeline: If Rails is available and the asset pipeline is enabled, the file is retrieved through the asset pipeline. E.g. if the URL is http://cdn.example.com/assets/email-fingerprint123.css, the file email.css is requested from the asset pipeline. That is, the fingerprint and the prefix (in this case assets is the prefix) are stripped before requesting it from the asset pipeline.

like image 70
Zzz Avatar answered Sep 19 '22 17:09

Zzz