Dynamic Select Box

Iw wrote:

I am experiencing problems retrieving information from the related drop
I can save information in the database (i.e. state_id and city_id are
getting saved in the Address table).

However on the Address's edit/update screen, the information from the
first "State" drop down is getting retrieved
properly but nothing is getting displayed in the second drop down -

I am using observe fields to retrieve data for the second drop down.
Please advise how to prepopulate information for the second drop down
based on the "id" stored in the database on Edits screens.

Thanks in advance for your help!


Ramanan wrote:
> Kevin Olbrich wrote:
>>>Posted via http://www.ruby-forum.com/.
>>>Rails mailing list
>> Take a look at this...
>> http://www.sciwerks.com/blog/2006/07/07/updating-select-controls-with-ajax/
>> _Kevin
>> www.sciwerks.com
> I have a working code where there are only 2 select boxes i.e.
> populating city when state is selected. I am having issues with
> populating locality based on selected city. Working with 2 dynamic
> select is straight forward. Working with more than 2 dynamic/cascading
> select box is a real issue.
> Thx. for your help

Posted via http://www.ruby-forum.com/.

You'd have to give us a bit more information about how you are
populating your select in the first place.


Iw wrote:

Here is relevant code:
The "city" in the second dropdown is not getting selected in Edit

Thank you so much for you help!

  <%= collection_select(:address, "state_id", State.find(:all), :id,
:state) %>
  <p id="address_city_container"><%= render :partial => 'select_city'

          <%= observe_field("address_state_id",
                  :frequency => 0.25,
                  :update => "address_city_container",
                  :url => {:controller => 'address', :action =>
                  :with => "'state_id=' + value")%>
<% --------
  - address_controller.rb

def filtered_city_select

   @cities = City.find_all_by_state_id(@params["state_id"])
    render :partial => 'select_cities'

def edit
   @address = Address.find(params[:id])
   @states = State.find_all
   @cities = City.find(:all, :conditions =>[ "state_id = ?",



partial _select_cities.rhtml

<% if @cities %>
<select name="address[city_id]" id="address_city_id">
     <option value="">-- Select City --</option>
     options_from_collection_for_select(@cities, "id", "city")
<% end %>

Posted via http://www.ruby-forum.com/.

Couple of points.
1. if you set the frequency of your observer to 0, it should fire off
whenever the value changes, and not every 0.25 seconds.

2. check your log files to see if you are getting errors thrown by the
filtered_city_select method

3. Don't use '@params', it's deprecated.

Does it work at all?