BvuRVKyUVlViVIc7
BvuRVKyUVlViVIc7

Reputation: 11811

Howto include application css into mailer views in Rails 3.1

Is there a way how I can add my normal application css files (which are scss/sass) to my mailer views without duplicating code?

Didn't find a solution on the net... :/

Upvotes: 2

Views: 1745

Answers (3)

heartpunk
heartpunk

Reputation: 2275

You probably don't want to do this. Much CSS won't work in email, and so your regular CSS isn't useful in that context. As an example, in a number of clients only inline (<sometag style='attribute:value'>...</sometag>) styles work.

Upvotes: 4

nkm
nkm

Reputation: 5914

As there are many email clients, the end user can use any of them to access their email. For example if you send a mail and inspect in gmail, your entire email will come under a div element of the body section of the email.

In an html page, we need to include the css file in the head section of the page. As this does not happens, the widely accepted way is writing inline css.

Note that all the css properties does not work with email templates.

References:

http://www.sitepoint.com/code-html-email-newsletters/

http://www.campaignmonitor.com/css/

Upvotes: 1

pduey
pduey

Reputation: 3786

You could include it in .../app/views/layouts/mailer.html.erb

But there is merit in tehgeekmeister's answer. The way I deal with it while limiting the amount of duplication, is to save a page on the web site as HTML, upload that to a email campaign system like mailchimp or constant contact, and when the email looks like I want there, save that into .../app/views/layouts/mailer.html.erb and tweak as necessary.

Annoying, but at least you'll ensure things look consistent and work well enough on multiple clients.

Upvotes: 1

Related Questions