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
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| %>
<%= f.label :State %> |
<%= select(:selected_district,:state, @states,{:include_blank=>'All'}) %> | <%=observe_field :selected_district_state, :frequency => 0.5, :update => "district_div",:url =>{:action => 'index' },:with => "'state='+encodeURIComponent(value)" -%>
_district_list.html.erb
I also tried with another RJS template.But it also din’t work 4 me
Thanks in advance,
Veena