How to display list of records in view without using any blocks or loops in RoR?

We can display list of records in a rails view file without writing any loops or blocks by using the collection object. Follow the following example.

<%= render :partial => "users/user", :collection => @users %> 

Create a partial user user the users folder in that partial we can display the results without writing any loops or blocks by simply using the user object.


<p> 
<strong>User Name:</strong> 
<%= user.name %> 
</p> 

<p> 
<strong>Location:</strong> 
<%= user.location %> 
</p>

No comments:

Post a Comment