Hi all,
Beginner''s question here: I''ve wondered, why I can''t
browse through
"nested" models (belongs_to/has_many).
My models: (http://gist.github.com/291956)
class Enterprise < ActiveRecord::Base
has_many :branches
has_many :people, :through => :branches
end
class Branch < ActiveRecord::Base
has_many :people
belongs_to :enterprise
end
class Person < ActiveRecord::Base
belongs_to :branch, :include => :enterprise
end
And finally viewing people: (http://gist.github.com/291953)
<h1>Listing people</h1>
<table>
<% @enterprises.each do |ent| %>
<tr>
<th colspan="8"><%= ent.name %></th>
</tr>
<% ent.branches.each do |branch| %>
<tr>
<th colspan="8"><%= branch.name %> (<%=
branch.people.count %>)</
th>
</tr>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Sex</th>
<th>Age</th>
<th>Email</th>
</tr>
<% branch.people.each do |person| %>
<tr>
<td><%=h person.first_name %></td>
<td><%=h person.last_name %></td>
<td><%=h person.sex %></td>
<td><%=h person.age %></td>
<td><%=h person.email %></td>
<td><%= link_to ''Show'', person %></td>
<td><%= link_to ''Edit'',
edit_person_path(person) %></td>
<td><%= link_to ''Destroy'', person, :confirm
=> ''Are you
sure?'', :method => :delete %></td>
</tr>
<% end %>
<% end %>
<% end %>
</table>
<br />
<%= link_to ''New person'', new_person_path %>
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.