Forum: Ruby on Rails accessing to a table (model)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F48b1167605be400c501f6ceb808c533?d=identicon&s=25 X-1101 (Guest)
on 2006-04-21 20:15
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
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-04-21 22:37
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

<h2>Employees</h2>
<% for employee in @employees %>
  <%= employee.name %><br />
<% end %>

<h2>Companies</h2>
<% for company in @companies %>
  <%= company.name %> has <%= company.employees.size %> employees.<br />
<% end %>
F48b1167605be400c501f6ceb808c533?d=identicon&s=25 X-1101 (Guest)
on 2006-04-22 01:12
thanks

Alex Wayne

my problem was solved....

your code help me so much

tankes
This topic is locked and can not be replied to.