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

  • Home
  • SEARCH
  • 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 7552049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:39:38+00:00 2026-05-30T10:39:38+00:00

What is the correct/rails/best practice way to call media specific (i.e. print, screen, etc)

  • 0

What is the correct/rails/best practice way to call media specific (i.e. print, screen, etc) css if using Rails 3.1 asset pipeline? I know this has been asked before, but all of the solutions I’ve seen seem very hacky and not the elegant Rails solution I’ve come to expect.

As far as I can tell, the suggested approach is to set up the stylesheets folder as follows:

assets
-stylesheets
--application.css
--application-print.css
--print
---custom-print.css
--screen
---custom-screen.css

the contents of application.css being

/*
*= require_self
*= require_tree ./screen
*/

the contents of application-print.css being

/*
*= require_self
*= require_tree ./print
*/

then to include the following in the layout

<%= stylesheet_link_tag 'application', media = 'screen, projection' %>
<%= stylesheet_link_tag 'application-print', media = 'print' %>

OK, so far so good.

BUT, in my case custom-print.css is being applied onscreen, and no css is being applied to printed output.

Also, this approach seem to affect images called from css. i.e. instead of looking for images in assets/images it is now looking for images in assets/stylesheets/screen. There may be something else going on here, as it seems to be only javascript css that is affected. I will do some more checking and report back.

So my question is, how are you dealing with media specific css in the Rails asset pipeline?What is regarded as best practice? And what am I doing wrong?

Thanks for your time!

  • 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-05-30T10:39:40+00:00Added an answer on May 30, 2026 at 10:39 am

    The problem is the syntax for the method call.

    stylesheet_link_tag 'application', :media => 'screen, projection'
    stylesheet_link_tag 'application-print', :media => 'print'
    

    In your code you were assigning to a local variable called media

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

Sidebar

Related Questions

What is the correct way in Rails w CarrierWave using Fog to delete/destroy records
What would be the correct rails way to create a row in the Database
Just installed rails 3.1 rc1 and am trying to grok the best way to
I'm new to rails and am unsure of the best way of doing this.
Is there a standard or best-practices way to test that an action in rails
Is there a pattern or best practice in Rails whereby we can specify, in
What's the best way to implement an interface that looks like this in rails?
I am thinking about the best way of including a JS library into rails
Given the Ruby-on-Rails MVC framework, what is the best way to handle a rating
I'm quite new to ruby/rails. I was wondering what is the best way to

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.