[Rails] drop downs

Brian Nice
Wed, 26 Apr 2006 12:18:32 -0000

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

<label
for="country">Country
<%=
options_from_collection_for_select(@countries, "id",
"descr") %>


  <%= observe_field(:country,
                 :update => "country_area",
                 :url => { :action => :find_areas_for_country },
                 :with => "''country=''+value")
%>

<label
for="country_area">Area
<%= render :partial => ''country_area''
%>


********** partial

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