Routes both nested and RESTful

I'll just show you an example. Let's say you wanted to nest a city
inside of a state, like:

   http://localhost/states/1/cities/3/

To nest the resources, you need to...nest them...in routes. :slight_smile: Like this:

  map.resources :states do |state|
    state.resources :cities
  end

Then, to add custom methods to each member (for example, if you wanted
to show the population for a city or something), then you would do
something like this:

  map.resources :states do |state|
    state.resources :cities, :member => { :population => :get }
  end

...where population is the action name and get is the HTTP method you
want to allow to be used on it. You could also do collection in the
place of member to allow things like
http://localhost/states/3/cities/average_population or something.

Keep in mind that when you nest resources, though, it also requires
you call url_for/link_to with nesting. For example, rather than...

   city_path the_city_id

...you need to do something like this:

   state_city_path the_state_id, the_city_id

This also applies to custom methods.

Hopefully that will give you enough to get going. :slight_smile:

--Jeremy