Stylesheet_link_tag :all versus :media =>all

27,591

Solution 1

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.

Solution 2

Please look at api docs. Here you have some quote from it:

stylesheet_link_tag :all # =>
  <link href="/stylesheets/style1.css"  media="screen" rel="stylesheet" type="text/css" />
  <link href="/stylesheets/styleB.css"  media="screen" rel="stylesheet" type="text/css" />
  <link href="/stylesheets/styleX2.css" media="screen" rel="stylesheet" type="text/css" />


stylesheet_link_tag "style", :media => "all" # =>
  <link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />
Share:
27,591
Lucy Weatherford
Author by

Lucy Weatherford

coder

Updated on April 04, 2020

Comments

  • Lucy Weatherford
    Lucy Weatherford about 4 years

    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?

  • Catfish
    Catfish almost 6 years
    Not sure where you got your example from the link you posted does not actually generate the type attribute
  • Marcin Pietraszek
    Marcin Pietraszek almost 6 years
    Did you notice that the answer was given 5+ years ago? ;)
  • TylerH
    TylerH about 2 years
    @MarcinPietraszek The age of an answer is irrelevant; if it doesn't work, that should be made clear to readers. If it needs updating to reflect changing environments, a comment is appropriate. If you don't want to remain responsible for an answer, you may mark it as a community wiki.