Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7891001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:30:17+00:00 2026-06-03T06:30:17+00:00

Instead of having the page include a style tag with a link where to

  • 0

Instead of having the page include a style tag with a link where to get the css from, which I could add to my view using rails’ stylesheet_link_tag helper method, I want to have the css inline directly inside the page.

This is what I came up with so far:

%style(type="text/css")=File.read(physical_asset_path("email.css"))

But I can’t find any rails’ helper method which gives me the physical path of an asset – physical_asset_path is just a dummy method invented by me.

Anybody knows how to get the physical path of an asset when using rails 3.2.x?

Is there an easier/ better way to get stylesheets – from css files inside the common rails assets paths – inline?

Use case: most email clients don’t access external sources (like css, images) without user confirmation. So to get the emails properly displayed I need to embed the CSS inside the emails’ HTML.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:30:19+00:00Added an answer on June 3, 2026 at 6:30 am

    Use premailer or premailer-rails3

    https://github.com/fphilipe/premailer-rails3
    or
    https://github.com/alexdunae/premailer

    Joe’s Nerd Party say:

    We also used the Premailer gem to automatically inline the linked
    stylesheet in the email views. Our email layout looks something like:

    %html
      %head
        = stylesheet_link_tag 'email'
    
        %style{:type => "text/css"}
          :sass
            @media all and (max-width: 480px)
              table#container
                width: auto !important
                max-width: 600px !important
             ... and so on for the mobile code
    
        %body 
          Email body here.
          %table
            Lots of tables.
    

    We include a stylesheet in the HTML. Premailer downloads it, processes
    it, and inserts the css rules inline in the HTML.

    The @media rules need to be inline in the email layout, since
    Premailer can’t handle those being in a separate css file yet.

    We use premailer-rails3 to integrate Premailer into Rails 3.
    Unfortunately, we found a bunch of bugs in premailer and
    premailer-rails3. Our forks of the projects are at
    https://github.com/joevandyk/premailer and
    https://github.com/joevandyk/premailer-rails3. The forks fix some
    encoding bugs, remove some weird css processing stuff done by
    premailer-rails3, allow premailer to not strip out embedded
    rules in the email layouts, and some other things.

    We also found a bug in sass-rails, where you can’t embed image-urls in
    inline sass code. See https://github.com/rails/sass-rails/issues/71
    Premailer-rails3 hooks into ActionMailer when the email actually being
    delivered, not just generated. When running tests, email is not
    actually sent, so the premailer-rails3 hooks don’t get ran during
    tests. I haven’t spent the time to see if it’s possible to get the
    premailer processing to run during tests, but that would be a nice
    thing to do.

    Also, our forks on premailer-rails3 assume that you want premailer to
    go out and actually download the linked CSS files. It should be
    possible to use the Rails 3.1 asset pipeline to get the processed css
    without downloading it. A very special thanks goes to Jordan Isip who
    did the super annoying job of making sure the emails look great in all
    the different clients out there. Writing that CSS/HTML did not look
    fun.

    Update:

    Roadie appears to be a better option. Thanks to Seth Bro for pointing it out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Instead of having an add() method in the repository, I would like to overload
Is there a way to view the latest debug message instead of having to
I'm having a problem where instead of reading a text file from the location
I have a big string having at most 100000 character. Instead of using string.charAt[index]
I'm currently using PHP to include multiple css (or js) files into a single
I'm having problem with going from mobile page to main page implemented in Joomla
Constant height so just left/right images should be necessary instead of having 4+, right?
In compiler design, why instead of having a caller or callee register saving arrangement,
motivation: I would like to create a utility class so that instead of having
I know Apple is big on having you use NS objects instead of true

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.