Topic: Use two models to make a list?
I have two tables in my database. One is Companies and the other is Cities. Each company has one city.
On the main page I want to list out company.name - company.address, city.name (and make the entire thing one link, if someone can help with that too)
So I was just kinda guessing at this, but can't figure out the answer. Anyway here's the wrong way.
@page_title = "Companies"
@company_pages, @companies = paginate :companies, :per_page => 10
@company = Company.find(params[:id])
@city = City.find(@company.city_id)
and part of the list.rhtml:
<% for company in @companies %>
<td><%=h @company.name %> - <%=h @company.address %>, <%=h @city.name %></td>
Thanks as always