Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.
I have a Rails question for anybody who can help...
I have a database table of faculty members for a school. The table has the following columns:
I'm trying to render a template to show details about each faculty member on a page. To do so, I tried the following:
<%= render :partial => 'list_entry', :collection => @faculty_members %>According to the Rails documentation, using the :collection property should force the partial to be rendered for each object in the collection. Each time the partial is rendered, a local variable whose name is the singular version of the collection name is created.
To make sure everything was working, I created a simple partial containing the following:
<li><%= faculty_member.last_name %></li>Of course, it didn't work. After toying around for a while, I got this to work:
<% @faculty_members.each do |f| %>
<%= render :partial => 'list_entry', :locals => { :faculty_member => f } %>
<% end %>As far as I can tell, these two commands should be doing the same thing. Am I missing something?
if you are doing:
<%= render :partial => 'foo', :collection => @bars %>
Then your erb partial code should be:
<li><%= foo.last_name %></li>
not bar.last_name. When you render a partial through a collection, the model fields are made available in a local var with the same name as your partial.
to quote the rails docs:
# Renders a collection of the same partial by making each element
# of @winners available through the local variable "person" as it
# builds the complete response.
render :partial => "person", :collection => @winners
1 to 3 of 3