Ruby On Rails Classroom image

Neha  Jaggi / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4 | 5 | 6 | 7|Last
Lessons:- Creating Microposts

The result appears in Listing 10.34

 

 

The code in Listing 10.34 has the advantage that it will break the test suite if we forget to require the user to sign in.

             The second change needed to get Listing 10.33 to work is to redefine the error messages partial so that

<%=  render  'shared/error messages' object:  f.object  %>

 

works. You may recall from Listing 7.22 that the error messages partial references the @user variable explicitly, but in the present case we have an @micropost variable instead. We should define an error messages partial that works regardless of the kind of object passed to it. Happily, the form variable f can access the associated object through f.object, so that in  

form for ( @user ) do  |f|

 

f.object is @user, and in

form for ( @micropostdo |f|

 

f.object is @micropost.

            To pass the object to the partial, we use a hash with value equal to the object and key equal to the desired name of the variable in the partial, which is what this code accomplishes: 

<%=  render 'shared/error messages', object: f.object  %>

 

In other words, object: f.object creates a variable called object in the error_messages partial. We can use this object to construct a customized error message, as shown in Listing 10.35.  

 

 
 
 
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)