Browsing nested models

Hi all,

Beginner’s question here: I’ve wondered, why I can’t browse through
“nested” models (belongs_to/has_many).

My models: (

class Enterprise < ActiveRecord::Base
has_many :branches
has_many :people, :through => :branches

class Branch < ActiveRecord::Base
has_many :people
belongs_to :enterprise

class Person < ActiveRecord::Base
belongs_to :branch, :include => :enterprise

And finally viewing people: (

Listing people

<% @enterprises.each do |ent| %>

<% ent.branches.each do |branch| %>

<% branch.people.each do |person| %>
    <td><%=h person.first_name %></td>
    <td><%=h person.last_name %></td>
    <td><%=h %></td>
    <td><%=h person.age %></td>
    <td><%=h %></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 %>

<% end %>

<% end %>
<% end %>

<%= %>
<%= %> (<%= branch.people.count
First name Last name Sex Age Email

<%= link_to ‘New person’, new_person_path %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs