Ruby On Rails Classroom image

Pooja  Negi / Student / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3|Last
Lessons:- Embedded Ruby

Listing 3.22 is our first example of Embedded Ruby, also called ERb. (Now you know why HTML views have the file extension .html.erb.) ERb is the primary template system for including dynamic content in web pages.13 The code  :title. 1

     <%  provide ( :title, 'Home' %>

 

indicates using <% ... %> that Rails should call the provide function and associate the string ’Home’ with the label title 4 Then, in the title, we use the closely related notation <%= ... %> to insert the title into the template using Ruby’s yield function:15  

< title >  Ruby on Rails Tutorial Sample App | <%=  yield ( :title ) %> < title >

 

  (The distinction between the two types of embedded Ruby is that <% ... %> executes the code inside, while <%= ... %> executes it and inserts the result into the template.) The resulting page is exactly the same as before, only now the variable part of the title is generated dynamically by ERb. We can verify that all this works by running the tests from Section 3.3.1 and see that they still pass:

$ bundle exec rspec spec/requests/static pages spec.rb

 

Of course, the views in Listing 3.22, Listing 3.23, and Listing 3.24 are still filled with all the HTML structure included in the layout, so we have to remove it, leaving only the interior contents. The resulting cleaned-up views appear in Listing 3.26, Listing 3.27, and Listing 3.28.  

 
 
 
image
Pooja   Negi

Skills    Ruby On Rails

Qualifications :- High School - SSN high school, College/University - HNBGU, College/University - SRHU,
Location :-Ranipokhari,Rishikesh,Uttarakhand,India
Description:- Student
Explore
 

  Students (0)