Search code examples
ruby-on-railsruby-on-rails-4sassactionmailerpremailer

Rails 4 x premailer x SASS: import stylesheet in mailer view


In my Rails 4 app, I use mailers to send out emails to users.

These mailers are working fine.

Now, I would like to style them, so I installed the premailer-rails gem (and the nokogiri gem).

I restarted my server.

Then, I created a specific stylesheet for mailers: public/assets/mailers.scss

I my mailer view, I added:

<head>
  <% stylesheet_link_tag mailers "public/assets/mailers.scss" %>
</head>

However, when a user opens the email in his inbox, for instance Gmail, the style is not applied.

Is there a particular way to include stylesheets in mailer views in Rails with premailer when using SASS?


Solution

  • What is mailers in you code snippet? If it is some helper that returns the name of the css file, then it's ok. See here in documentation what is expected by stylesheet_link_tag method.

    Anyway, whatever it is, you are missing = sign, and you need it in order to render anything into you view:

    <head>
      <%= stylesheet_link_tag mailers "public/assets/mailers.scss" %>
    </head>