Rails: displaying a collection of models using a specific kind of html

I have the following simple problem with rails.

Say I have a User model. In the view, if I do this:

<%= render User.all %> 

Viewing files in views / user / _user.html.erb will be called and printed for each of the users.

How can I change this to use a specific view? I need something like:

 <%= render :data=>User.all :template=>"user/_user_2ndview.html"%> 

Any help? thanks in advance

+6
source share
1 answer

You can use the collection option:

 <%= render :collection => User.all, :partial => "users/user2ndview", :as => :user %> 

The view should be placed in views / users / _user2ndview

See the Rails Guide to rendering collections for more information.

+8
source

All Articles