Ruby On Rails Classroom image

Neha  Jaggi / Professional / Web Technology

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

Embedded Ruby

We’ve achieved a lot already in this section, generating three valid pages using Rails controllers and actions, but they are purely static HTML and hence don’t show off the power of Rails. Moreover, they suffer from terrible duplication:

  • The page titles are almost (but not quite) exactly the same.
  • ‘‘Ruby on Rails Tutorial Sample App’’ is common to all three titles.
  •  The entire HTML skeleton structure is repeated on each page.

This repeated code is a violation of the important ‘‘Don’t Repeat Yourself’’ (DRY) principle; in this section and the next we’ll ‘‘DRY out our code’’ by removing the repetition.   Paradoxically, we’ll take the first step toward eliminating duplication by first adding some more: We’ll make the titles of the pages, which are currently quite similar, match exactly. This will make it much simpler to remove all the repetition at a stroke.

The technique involves using Embedded Ruby in our views. Since the Home, Help, and About page titles have a variable component, we’ll use a special Rails function called provide to set a different title on each page. We can see how this works by replacing the literal title ‘‘Home’’ in the home.html.erb view with the code in Listing 3.22.

 

Listing 3.22 The view for the Home page with an Embedded Ruby title.
app/views/static_pages/home.html.erb

 

 

 
 
 
image
Neha  Jaggi

Skills    Ruby On Rails

Qualifications :- High School - , College/University - Graphic Era Hill University, Dehradun, College/University - ,
Location :-Dehradun,Dehradun,UTTARAKHAND,India
Description:-

Experienced Software Developer with a demonstrated history of working in the Information Technology and services industry. Skilled in Web Technologies (Ruby on Rails, PostgreSQL, php, Laravel and AJAX). 


Explore
 

  Students (0)