views:

147

answers:

2

Hello, I'm new to Ruby on Rails, and need some help.

I'm working on a web application which can be used to keep track of cars. There are two models, one which represents makes (Saab, Honda, Toyota, etc) and another which represents models (Civic, Miata, PT Cruiser, etc). They have a "has_many" relationship:

script/generate scaffold make name:string

script/generate scaffold model name:string make_id:integer

I created a view with two select boxes (created using the select helper method), one for makes and one for models.

Here's what I'm having trouble figuring out how to do: I would like for the second select box to be populated only with the models which correspond to the make selected in the first. When the make changes in the first select box, so should the models in the second.

Thanks guys!

A: 

You just have to write a piece of JavaScript that submits the form via AJAX when the "make" selectbox changes and then, on the server-side, use an RJS view that will get your names into second selectbox.

Jakub Lédl
+3  A: 
klochner
Sorry, but I can't follow this code. I need a more complete example. I'm a brand new beginner.
Kara
klochner