These were all really helpful -- I really appreciate the depth of the
responses. I now only have a problem with using a collection in
rendering a partial. I think I followed the exact rules, but here is
what I did anyway:
The layout (app/views/layouts/application.html.erb):
...
<body>
<%= yield :title %>
<br />
<%= yield %>
</body>
...
the controller (app/controllers/people/people_controller.rb):
class PeopleController < ApplicationController
layout "application" # default, but specified anyway
def index
@people = Person.find(:all)
end
end
in the view (app/views/people/index.html.erb):
<% content_for :title do -%>
<h3>Listing People</h3>
<% end -%>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<%= render :partial => "people", :collection => @people %>
</table>
in the partial (app/views/people/_people.html.erb):
<tr class=<%= cycle("odd","even")%>>
<td><%= h person.first_name %></td>
<td><%= h person.last_name %></td>
</tr>
----
I made sure I had data available for these people (using
script/console), but I got an error rendering this partial:
undefined local variable or method 'person' for #<ActionView::....>
in app/views/people/_people.html.erb
I realize the partial doesn't recognize the person object, but I thought
rails handled the conversion between the collection @people of the view
to the iteration in the partial. So.. I'm not sure what I might be doing
wrong. Help is very appreciated - thanks!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---