How do I load my print.css
file in Rails 3.1?
Asked
Active
Viewed 2,949 times
-3
2 Answers
3
Not sure if you want the print css which applies to print media
The following should serve the purpose - stylesheet_link_tag "print", :media => "print"

Jayendra
- 52,349
- 4
- 80
- 90
-
I want to style the page for the printer, that's right. I'm not sure why <%= stylesheet_link_tag "application" %> <%= stylesheet_link_tag "print", :media => "print" %> turns into How to eliminate the line print.css for media="screen" – Thomas Sep 18 '11 at 17:25
-
:media => print parameter would help you apply styles only to page you want to print. – Jayendra Sep 18 '11 at 17:28
-
Sure, but why does it insert into my file? Do you have an idea how to eliminate it? – Thomas Sep 18 '11 at 17:30
-
do you have stylesheet_link_tag :all in the layout ? Cause it seems its loading all the styles from your asset folder and would have media screen attached to it by default. – Jayendra Sep 18 '11 at 17:36
-
No, I have only <%= stylesheet_link_tag "application" %> and <%= stylesheet_link_tag "print", :media => "print" %> – Thomas Sep 18 '11 at 17:36
-
So how is the additional style.css loaded into the page ? – Jayendra Sep 18 '11 at 17:40
-
That's how: <%= stylesheet_link_tag "application" %> – Thomas Sep 18 '11 at 17:56
-
I am experiencing this too. I changed `stylesheet_link_tag "application"` to `stylesheet_link_tag "application", :media => "screen"` and I have `stylesheet_link_tag "print", :media => "print"`. This resolves the HTML output (i.e. `` but still, the effects of the `print.css` affects all screen media types. – Igbanam Dec 13 '11 at 15:15
1
Actually, if you take a look in the application.css document you would see :
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree .
*/
It means that application.css will be included (require_self) and also the others CSS in the stylesheets folder (require_tree .).
I'm a beginner in Rails so I cannot go further in the explanation! Search any informations about require_self, require_tree and SASS language.

Nicolas Renon
- 3,881
- 2
- 15
- 13
-
Take a look at this [topic](http://stackoverflow.com/questions/7134034/using-rails-3-1-assets-pipeline-to-conditionally-use-certain-css) – Nicolas Renon Jan 30 '12 at 18:42