Topic: ajax related question , i don't know how can i do that

hello everyone
There is something i want to do but i don't know how can i do that, what do i want to do is:
select_tag with some countries , and when you choose any country from select , it loads cities belongs to that country beneath the select_tag in the same page without submit buttons, can anyone told me how can i do that please
Thanks

Re: ajax related question , i don't know how can i do that

For starters,  just get the AJAX select working

You need you're select tags onchange event to fire off an AJAX call to your controller.

It might look something like this:

<%= f.select 'countries', Country.all.collect {|c| c.CountryName, c,id},{},{
   :onchange=>remote_function(:url=> {:action=>:get_cities}, 
                                               :update=>'my_city_pulldown',
                                               :success=>"$('#my_city_pulldown').show()",
                                               :with=>"'from_country=' + $(this).value()")
   }

Now put a route routes.rb (sorry this is 2.X, not 3.0 syntax)

map.connect '/country/get_cities', :action=>'get_cities'

Then in your countries controller

def get_cities
  # go get your cities,  don't know how you set it up though, I'll assume
   @cities = City.find(:all, conditions=>['country = ?', params[:from_country])
   rslt = ''
   @cities.each do |c|
      rslt += "<a href='/link_to_city/#{c.id}'>#{c.Name}</a>"
   end
   render (:text=>rslt)
end

Once you have this working,  you'll need to arrange for an HTML element with an id of 'my_city_pulldown', and it should initially be styled display:none, like this

<div id="my_city_pulldown" style="display:none">
</div>

When the AJAX is called, it  with will stick whatever get_cities renders into that div, and if the AJAX call is successful,  that div will get displayed.  You'll have a crude little pop-menu.  You'll have to muck around with css to get it positioned where you want it.

Good luck!

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.