I''m having trouble getting a second drop down populated based on the value from the first drop down. I''ve tried following some of the examples posted, but haven''t had any success. I''m new to RoR so any help would be appreciated. When the first drop down''s value gets changed, it calls the correct method in the controller and even finds the correct country areas, but the results are not getting displayed in the partial - the second drop down just remains blank. Thanks for the help! ************* Controller def new @trip = Trip.new @countries = Country.find(:all) @country_areas = [] end def find_areas_for_country @country_areas = CountryArea.find(:all, :conditions => ["country_id = :country", params]) render(:partial => "country_area", :collection => @country_areas) end *********** form <tr> <td><label for="country">Country</label></td> <td><select id="country" name="country"><%= options_from_collection_for_select(@countries, "id", "descr") %> </select></td> </tr> <%= observe_field(:country, :update => "country_area", :url => { :action => :find_areas_for_country }, :with => "''country=''+value") %> <tr> <td><label for="country_area">Area</label></td> <td><%= render :partial => ''country_area'' %></td> </tr> ********** partial <select id="country_area" name="country_area"> <%= options_from_collection_for_select(@country_areas, "id", "descr") %> </select> -- Posted via http://www.ruby-forum.com/.
Brian Nice wrote:> *********** form > <tr> > <td><label for="country">Country</label></td> > <td><select id="country" name="country"><%= > options_from_collection_for_select(@countries, "id", "descr") %> > </select></td> > </tr> > <%= observe_field(:country, > :update => "country_area", > :url => { :action => :find_areas_for_country }, > :with => "''country=''+value") %> > <tr> > <td><label for="country_area">Area</label></td> > <td><%= render :partial => ''country_area'' %></td> > </tr> > > ********** partial > <select id="country_area" name="country_area"> > <%= options_from_collection_for_select(@country_areas, "id", "descr") %> > </select>You don''t seem to have a div or span with an id of country_area. tthe :update => ... bit of the observe_field is looking to replcace the contents of an element with the results of the action, you need a div to render into. Alan. -- Posted via http://www.ruby-forum.com/.
Alan Francis wrote:> You don''t seem to have a div or span with an id of country_area. tthe > :update => ... bit of the observe_field is looking to replcace the > contents of an element with the results of the action, you need a div to > render into.Jyst noticed the countray_area id is used inside the partial. this won''t work as the particl needs rendered *into* country_area. In your case, that should probably be the td(*). Alan (*)But be wary of DOM manipulation and tables in IE -- Posted via http://www.ruby-forum.com/.
Alan Francis wrote:> Alan Francis wrote: > >> You don''t seem to have a div or span with an id of country_area. tthe >> :update => ... bit of the observe_field is looking to replcace the >> contents of an element with the results of the action, you need a div to >> render into. > > Jyst noticed the countray_area id is used inside the partial. this > won''t work as the particl needs rendered *into* country_area. In your > case, that should probably be the td(*). > > Alan > (*)But be wary of DOM manipulation and tables in IEThanks that seems to work! I also had to change the line in the controller to use :object rather than :collection render(:partial => "country_area", :object => @country_areas) Thanks again -- Posted via http://www.ruby-forum.com/.