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)
Listing people
<%= ent.name %> | ||||
---|---|---|---|---|
<%= branch.name %> (<%= branch.people.count %>)</ th> |
||||
First name | Last name | Sex | Age |
<%= link_to ‘New person’, new_person_path %>