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 =
@state =
@city =
@category =
def create[:country])[:state])
redirect_to :action =>‘list’
def list

and the models are

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

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

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

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

and the view files are:


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

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

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

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


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

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

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

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

<%= 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