Ruby On Rails Classroom image

Pooja  Negi / Student / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2|
Lessons:- Partial Refactoring

Here we call render not on a string with the name of a partial, but rather on a user variable of class User; 6 in this context, Rails automatically looks for a partial called _user.html.erb, which we must create (Listing 9.37).

 

 

This is a definite improvement, but we can do even better: We can call render directly on the @users variable (Listing 9.38).

 

Here Rails infers that @users is a list of User objects; moreover, when called with a collection of users, Rails automatically iterates through them and renders each one with the _user.html.erb partial. The result is the impressively compact code in Listing 9.38. As with any refactoring, you should verify that the test suite is still green after changing the application code:

$ bundle exec rspec spec/

 

 

 
 
 
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)