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 ? :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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! -- Phlip http://www.oreilly.com/catalog/9780596510657/ ^ assert_xpath http://tinyurl.com/yrc77g <-- assert_latest Model --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I would use an observer like this: <%= select_tag :foo, [1,2,3,4], 1) %> <%= observe_field :foo, :url => {:action => :bar}, :with => ''foo'' -%> Make sure you include the :with => ''foo'' as that will become params[foo] and will be equal to the selected value in the select see: http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000535 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 ? > :( >-- Sincerely, William Pratt http://www.billpratt.net billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---