Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stylesheet_link_tag :all versus :media =>all

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?

like image 578
Lucy Weatherford Avatar asked Apr 04 '13 08:04

Lucy Weatherford


2 Answers

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.

like image 92
rorra Avatar answered Oct 16 '22 06:10

rorra


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" />
like image 23
Marcin Pietraszek Avatar answered Oct 16 '22 07:10

Marcin Pietraszek