Ruby for Rails

hi friends,

  I am new to ruby and i need a help from any one of u.
       I have got four tables and all i have to get the thing is i

need to take the Id from one table and pass it in to the another table.
Similarly in the descending order, one to two, to three, to four. ie ,
first tables primary key is the second one’s foreign key. second
table,first table primary key is the third tables primary key and so
on… Now i have to get that functionality in the manner like, in one
form i need to get four labels where in i can provide and store in to
the database… and on submitting, it will lead us to the listing page,
where in i had maintained drop down list. But the thing is i am getting
all the contents. I have to get only those first table id contents from
four tables , through foreign reference.

       In the database also it is not passing that id values in to

the child tables.

def new
@country = Country.new
@state = State.new
@city = City.new
@category = Category.new
end
def create
@country=Country.new(params[:country])
@state=State.new(params[:state])
#@country.states.create(params[:id])
@city=City.new(params[:city])
#@country.cities.create(params[:id])
#@state.cities.create(params[:id])
@category=Category.new(params[:category])
#@country.categories.create(params[:id])
#@state.categories.create(params[:id])
#@city.categories.create(params[:id])
@country.save
@state.save
@city.save
@category.save
redirect_to :action =>‘list’
end
def list
end

and the models are

class Country < ActiveRecord::Base
has_many :states
has_many :cities
end

class State < ActiveRecord::Base
belongs_to :country
has_many :cities
end

class City < ActiveRecord::Base
belongs_to :state
belongs_to :country
end

class Category < ActiveRecord::Base
belongs_to :state
belongs_to :country
belongs_to : city
end

and the view files are:

list.rhtml

Select Country
<%= select('name', 'id', Country.find_all.collect {|country| country.name}) %>

Select State
<%= select('name', 'id', State.find_all.collect {|state| state.name}) %>

Select City
<%= select('name', 'id', City.find_all.collect {|city| city.name}) %>

Select Category
<%= select('name', 'id', Category.find_all.collect {|category| category.name}) %>

new.rhtml

<%= start_form_tag :action => ‘create’ %>

Country
<%= text_field 'country', 'name' %>

State
<%= text_field 'state', 'name' %>

City
<%= text_field 'city', 'name' %>

Category
<%= text_field 'category', 'name' %> <%= submit_tag "Add" %> <%= end_form_tag %>

please have a look in to my coding and help me out with some suggestions
or modifications

Expecting a help from rubians

thank u