Drop downs

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

Country <%= options_from_collection_for_select(@countries, "id", "descr") %> <%= observe_field(:country, :update => "country_area", :url => { :action => :find_areas_for_country }, :with => "'country='+value") %> Area <%= render :partial => 'country_area' %>

********** partial

<%= options_from_collection_for_select(@country_areas, “id”, “descr”) %>

Brian N. wrote:

*********** form

Country <%= options_from_collection_for_select(@countries, "id", "descr") %> <%= observe_field(:country, :update => "country_area", :url => { :action => :find_areas_for_country }, :with => "'country='+value") %> Area <%= render :partial => 'country_area' %>

********** partial

<%= options_from_collection_for_select(@country_areas, “id”, “descr”) %>

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.

Alan F. 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

Alan F. wrote:

Alan F. 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

Thanks 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