Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are render @users and render 'new' different?

In RoR, I sometimes see:

render @users

or

render 'new' 

How are the two different?

like image 324
user627119 Avatar asked Dec 16 '12 02:12

user627119


1 Answers

In short, render @users is rendering a collection of objects of type User with a partial file named _user.html.erb, and render 'new' is rendering the new action & is equivalent to render :action => new.

Best to review the Layouts and Rendering in Rails page in the Ruby on Rails Guides to understand how these two work & where they can be used appropriately, and the various in-built assumptions that make these and many other convenient render methods possible.

like image 196
Prakash Murthy Avatar answered Nov 01 '22 07:11

Prakash Murthy