Ok so I am building a directory that is organized by state, county,
city, zip. I created tables for each of them, so i have a table for
states, counties, cities, and zips. Also in each table I have a title
column and a corresponding reference _id table. Meaning in my states
table i have a title column and a county_id colomun. same with all the
other tables.
In my models folder for state.rb I have the following
class State < ActiveRecord::Base
has_many :counties
end
And in my models folder for county.rb I have the following
class County < ActiveRecord::Base
belongs_to :state
has_many :cities
end
I have also generated a scaffold for state, county, city, and zip, all
with a title column.
I also modified the new action for each one so I am able to select
what counties belong to which states, and what cities belong to which
counties etc.
I created a new display controller so I can view my new directory and
it starts off with an index file that shows all the states like this
Listing States
<%= link_to state.title, {:controller => 'display', :action => 'counties'} %> |
And then I have another file in my display folder view called counties
and it has the following in it.
Listing counties
<%= link_to county.title, {:controller => 'display', :action => 'cities'} %> |
And it continues, however when u click on a particular state I only
want it to show the counties that belongs to it and I do not know how
to do that. Any help would be greatly appreciated. Thanks in advance.