Ruby On Rails Classroom image

Neha  Jaggi / 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
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)