Ruby On Rails Classroom image

Neeraj  Amoli / 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
Neeraj  Amoli

Skills    Ruby On Rails

Qualifications :-
Location :-Dehradun,Dehradun,Uttrakhand,India
Description:-

I have 3 year experience as a Software Engineer. My Skilled are Android Development (Java), ROR Development .   


Explore
 

  Students (0)