Accessing to a table (model)


#1

i don’t know how to access to the collecction of data that exists in
other model.

for example
i generate two scaffold : company and employe

both have a controller, a model and 5 files in the views:
_form.rhtml, list.rhtml, new.rhtml, edit.rhtml and show.rhtml

the views are working very well, but each access just one table: company
or employe

my problem is any simple, but i can’t do it

in the views that show the list of the employes i want to show the list
of companies

resume:
in the same page show both list.

help!
please


#2

X-1101 wrote:

i don’t know how to access to the collecction of data that exists in
other model.

for example
i generate two scaffold : company and employe

both have a controller, a model and 5 files in the views:
_form.rhtml, list.rhtml, new.rhtml, edit.rhtml and show.rhtml

the views are working very well, but each access just one table: company
or employe

my problem is any simple, but i can’t do it

in the views that show the list of the employes i want to show the list
of companies

resume:
in the same page show both list.

help!
please

#Controller

def list
@employees = Employees.find(:all)
@companies = Company.find(:all)
end

#View list.rhtml

Employees

<% for employee in @employees %> <%= employee.name %>
<% end %>

Companies

<% for company in @companies %> <%= company.name %> has <%= company.employees.size %> employees.
<% end %>

#3

thanks

Alex W.

my problem was solved…

your code help me so much

tankes