Over 4 years ago, I wrote a tutorial for doing dynamic (cascading) select boxes.
Still getting comments and emails to this day. Mostly asking how to get this working with rails 3, which has moved from prototype to jquery.
So here's a tutorial for getting 3 select boxes to trigger updates for each other.

First set things up:

I just used the html5 haml twitter bootstrap, etc template. Really useful.

If you need data, here's what I used - put this in your db/seeds.rb file:

Next, setup your model associations:

Genres have many artists.
Artists have many songs.
Genres have many songs through artists.

I'm just using a home controller to setup variables for the index page as well as setup variables for use in the dynamic updating:

Now the view just has the 3 select boxes and the unobtrusive javascript (triggered onchange) to make the ajax calls for updating:

We need our rjs files for updating the select boxes, one for the songs (when artist changes) and one for the artists and songs (when genre changes):

Our routes are simple:

That's it.

UPDATE: Here's an erb alternative for index.html.

And the js.haml can be converted to js.erb by taking #{...} and converting to :

I know this is beyond the scope of your tutorial, but — let’s say I want to take the results of all three selects, and pass those as parameters to a controller? On the final select, render a partial with the params ?

In your example, the elements come back in the order in which they are in the database (song1, then song2, then song3). Of course, in the “real world” the data would be more like “Good Vibrations”, “Surfer Girl”, and “I Get Around”. What if you want the select list to be in alphabetical order? Normally I would pull the data like @songs = Song.find(:all, :order => ‘title ASC’) - how would you do that with the .map?

You can do this many ways.
1) In the models: You can set the default order of all the models. Plus for the has_many associations, you could add an order clause: has_many :songs, :order => :title
2) In the controller: Instead of Genre.all, you would do Genre.order(:name), or instead of artist.songs, you would do artist.songs.order(:title)

First of all, thanks for this. It has been an excellent teaching tool for the collection_select dropdown box method for me. That being said, I’m stuck. My dropdown menus aren’t populated with any data! I followed the tutorial exactly the first two times through. THEN I copied and pasted your code to make sure it wasn’t my mistyping that had screwed things up. No luck still. Any suggestions for where my hangup might be?