Reputation: 2698
I have the following simple problem with rails.
Let say I have a model User. In a view, if I do:
<%= render User.all %>
The file view in views/user/_user.html.erb will be called and printed for each of the users.
How can I change this to use an specific view? I need something like:
<%= render :data=>User.all :template=>"user/_user_2ndview.html"%>
Any help? Thanks in advance
Upvotes: 6
Views: 1011
Reputation: 72504
You can use the collection
option:
<%= render :collection => User.all, :partial => "users/user2ndview",
:as => :user %>
The view must be placed in views/users/_user2ndview
See the Rails guides on rendering collections for more details.
Upvotes: 8