Mix Mix wrote:
hi everybody, how can i do something like this? i have a select with something to choose, when you choose one of them the select must be reload with new records, until the records are finished (2 or 3 levels)...i think that i can do this using ajax, but how? or another way is to have a first select, when is chose something from that another select appear with the new records to select.... any idea ?
Let's take the model of countries, states, and cities. Unless your users are creating countries, the list of all cities never changes, even if it is very large.
So let's preload that entire data object by building a Ruby Hash of countries, states, and cities, and use to_json to extrude all of it as a JavaScript variable. Then use javascript_tag to stick this into the <head> of your page. (If you worry about server load, you could just put the list into a .js file, and then only the browsers who haven't seen the list yet will load it.)
Then you use JavaScript to populate the select, and when the user picks an item you hook the onchange event, and use more JavaScript to repopulate.
This is a fairly well-established pattern, so you should be able to Google for it!