Ruby On Rails Classroom image

Anil  Bist / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  ||
Lessons:-CSS revisited

CSS revisited

It’s time now to revisit the line from Listing 4.1 used in the layout to include the cascading style sheets:

<%=   stylesheet link tag  "application",  :media =>  "all" %>

We are now nearly in a position to understand this. As mentioned briefly in Section 4.1, Rails defines a special function to include stylesheets, and

stylesheet link tag   "application",   :media =>   "all"  

is a call to this function. But there are two mysteries. First, where are the parentheses? In Ruby, they are optional; these two lines are equivalent:

# Parentheses on function calls are optional.
stylesheet link tag   ("application",  :media =>   "all")
stylesheet link tag   "application",   :media =>  "all"

Second, the :media argument sure looks like a hash, but where are the curly braces? When hashes are the last argument in a function call, the curly braces are optional; these two lines are equivalent:  

# Curly braces on final hash arguments are optional.
stylesheet link tag   "application",   { :media =>  "all" }
stylesheet link tag   "application",    :media =>   "all"

So, we see now that the line

stylesheet link tag  "application":media =>  "all"

calls the stylesheet_link_tag function with two arguments: a string, indicating the path to the stylesheet, and a hash, indicating the media type. Because of the <%= %> brackets, the results are inserted into the template by ERb, and if you view the source of the page in your browser you should see the HTML needed to include a stylesheet (Listing 4.7). (You may see some extra things, like ?body=1, after the CSS filenames. These are inserted by Rails to ensure that browsers reload the CSS when it changes on the server.)

Listing 4.7 The HTML source produced by the CSS includes

<link  href=  "/assets/application.css" media= "all"  rel=  "stylesheet"
type=  "text/css"  />

If you actually view the CSS file by navigating to http://localhost:3000/assets/ application.css, you’ll see that (apart from some comments) it is empty. We’ll set
about changing this in Chapter 5.

 
 
 
image
Anil  Bist

Skills    Ruby On Rails

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)