Stylesheet_link_tag :all versus :media =>all

Lucy Weatherford picture Lucy Weatherford · Apr 4, 2013 · Viewed 26.3k times · Source

I created a new Rails application from a scaffold, but the tutorial claims the following will appear:

<%= stylesheet_link_tag    "application", :media => "all" %>

while I got:

<%= stylesheet_link_tag    :all %>

What is the difference between them? Which should I use? Why?

Answer

rorra picture rorra · Apr 4, 2013

Using

<%= stylesheet_link_tag    "application", :media => "all" %>

will include the stylesheet named application.css, you can have files like application.css.sass or application.css.scss or any other extensions and rails will compile the css file with the right stylesheet engine and serve the application.css file.

The attribute "media=all" is actually a css attribute, which means that the css will be included for all the medias, like when browsing the website, when printing the screen, etc. You can find more information about the media attribute on this link.

By using

<%= stylesheet_link_tag    :all %>

you will include all the stylesheets that you have on your app/assets/stylesheets directory.

You can find more information on this link.