Stylesheet_link_tag: all versus: media => all

I created a new Rails application with scaffold, but the tutorial states the following:

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

while i got:

 <%= stylesheet_link_tag :all %> 

What is the difference between the two? What should i use? Why?

+7
source share
4 answers

Using

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

will include a stylesheet called 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 using the correct stylesheet engine and serve the application.css file .

The media = all attribute is actually a css attribute, which means that css will be enabled for all media, for example, when viewing a website, when printing a screen, etc. You can find more information about the media attribute at this link.

Using

 <%= stylesheet_link_tag :all %> 

You will include all the stylesheets that you use in the app / assets / stylesheets directory.

You can find more information at this link.

+18
source

Check out the api docs . Here you have a quote from this:

 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" /> 
+1
source

The second option is not a media type, it includes all .css from the stylesheets directory in the asset-free pipeline project.

 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" /> 
0
source

stylesheet_link_tag also accepts a parameter for the media attribute in the generated

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

Will produce:

 <link href="/stylesheets/killer.css" media="all" rel="stylesheet" type="text/css" /> 

If instead you want to include all the stylesheets in the stylesheets directory, simply call:

 < %= stylesheet_link_tag :all %> 

from wiki rails:

Note that by default stylesheet_link_tag will look for stylesheets in the / public / stylesheets directory of your application. In addition, when no other parameters are passed to stylesheet_link_tag, the type attribute is set to text / css, the media is set to the screen, and the relationship is set to the stylesheet. In addition, you do not need to include the .css extension in the file name when passing the file name parameter. You can enable it, but as long as your CSS stylesheets are named with the .css extension, there is no need to do so. Note that if you enable the file extension, Rails will no longer find the file with the .css extension for this call. For example, if you want to include a stylesheet named my_style.new.css, not enough:

0
source

All Articles