Ruby On Rails Classroom image

Pooja  Negi / Student / Web Technology

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

In addition to coming equipped with a large number of built-in functions for use in the views, Rails also allows the creation of new ones. Such functions are called helpers; to see how to make a custom helper, let’s start by examining the title line from Listing 4.1:

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

 

 

But what if we don’t provide a title? It’s a good convention to have a base title we use on every page, with an optional page title if we want to be more specific. We’ve almost achieved that with our current layout, with one wrinkle: As you can see if you delete the provide call in one of the views, in the absence of a page-specific title the full title appears as follows:

Ruby on Rails Tutorial Sample App |  

          In other words, there’s a suitable basetitle, but there’s also a trailing vertical bar character | at the end.

To solve the problem of a missing page title, we’ll define a custom helper called full_title. The full_title helper returns a base title, ‘‘Ruby on Rails Tutorial Sample App,’’ if no page title is defined, and adds a vertical bar followed by the page title if one is defined (Listing 4.2).1  

 
 
 
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)