Ruby On Rails Classroom image

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