Displaying hash for has_many

Let me start off by saying I am very much a beginner.

I currently have 2 models - Person, and address.

I am currently trying to display a person and their address on the
“index” page in the person section.

I can create a person and multiple addresses all at once using the
Advanced Rails Recipe, and the foreign key saves fine, but now I am
trying to get the person to display with their associated address on
the index page and am lost.

<% if @people -%>

<% end -%>

The above code spits out the proper string for all the people I want,
however, I can’t seem to figure out how to spit out their addresses as

def index
@people = Person.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @people }

The above is what I have in my person controller currently, and I have
no idea where to go from here to get this done. Any help would be
greatly appreciated.

Assuming you have set up relationships correctly either has_one or
has_many between Person and Address. It should be as simple as
@person.address (or @person.address1 etc.). The @person instance
variable will carry the associated data with it so you simply have to
use the “.” operator to get the address data.

.to_json takes an :include param–have a look at the activerecord docs.