Clem,
You will likely find it easier and more efficient to offload some of the work the the models and controller. It looks like what you want to do is print out data from two table that have a beongs_to/has_many relationship. Here is a basic example:
Models: class Person < ActiveRecord::Base has_many :addresses # addresses is plural b/c their can be more than one end
class Address < ActiveRecord::Base belongs_to :person # person is singular b/c their can be only one end
Controller: class PersonController < ApplicationController def list # use :include to load all the people and their addresses with one database query (join) @people = Person.find(:all, :include => :addresses) end end
View: <% for person in @people -%> <%= person.name %><br /> <% for address in @person.addresses -%> <%= "#{address.street}, #{address.city}, #{address.state}, #{address.zip} %><br /> <% end -%> <% end -%>
You could also use partials to construct the view making you code more reusable (you can call the same partial from somewhere else).
View with partials: <%= render :partial => 'person', :collection => @people %>
_person partial: <%= person.name %><br /> <%= render :partial => 'address', :collection => person.addresses %>
_address partial: <%= "#{address.street}, #{address.city}, #{address.state}, #{address.zip} %><br />
Hope this gets you going in the right direction.
Aaron