I'm still new to Rails so pardon me if I misunderstand your issue, but I believe the answer is to use
1) collection_select 2) :onchange You'll probably find your way here : http://pullmonkey.com/2008/03/30/dynamic-select-boxes-ruby-on-rails/ Christophe Le 8 avr. 2010 à 11:00, Veena Jose a écrit : > Hello frnds, > I hav 2 select boxes. > First select box is populated with all the "distinct states".On > selecting a state I want the 2nd selct box to be populated with its > corresponding "districts". > On selecting the district,I want some data to be displayed for that > corressponding district. > I am able to display the data on selecting the "district".(using RJS > template and partial) > But the 2nd select box is always populated with all the districts.It is > not populated accoring to the selection of first selectbox. > Can you help me in solving this problem? > > things that i tried > -------------------- > 1. > Readings controller > def index > @states= Station.find(:all, :select=>'state', :order =>"state").map{ > |t| t.state }.uniq > if (params[:state] ) > district=Station.find_all_by_state(params[:state]) > @districts = Station.find(district, > :select=>'district',:order=>"id") > else > @districts = Station.find(:all, :select=>'district').map{ |t| > t.district }.uniq > end > end > > readings/index.html.erb > > <% form_for :selected_district do |f| %> > <table cellspacing="10"><tr><td> > <b> <%= f.label :State %></b></td> > <td><%= select(:selected_district,:state, > @states,{:include_blank=>'All'}) %></td> > <%=observe_field :selected_district_state, :frequency => 0.5, :update => > "district_div",:url =>{:action => 'index' },:with => > "'state='+encodeURIComponent(value)" -%> > <div id="district_div"> > <%= render :partial => "district_list" %> > </div> > </tr> > </table> > <%end%> > > _district_list.html.erb > > <td><b>District :</b></td> > <td> > <%= select(:selected_district,:district, > @districts,{:include_blank=>'All'},{:onchange > =>remote_function(:url=>"/readings/show_readings_for_station",:with > =>"'district='+document.getElementById('selected_district_district').value")} > ) %> > </td> > > I also tried with another RJS template.But it also din't work 4 me > > > Thanks in advance, > Veena > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

