Good to know, Because AJAX is involved and you're new in rails, I am assuming you want to have it work using Prototype library and RJS.
Some pages to let you understand Prototype and JQuery AJAX frameworks in rails... http://www.slideshare.net/remy.sharp/prototype-jquery-going-from-one-to-the-other http://www.prototypejs.org/ http://wiki.github.com/madrobby/scriptaculous/ 1. Now, things you will need to make AJAX work. If you happen to have a layout file for your application, it should load the javascripts necessary to support AJAX operations. <%= javascript_include_tag :defaults %> will do it for you. It will include prototype and effects, etc. javascript files. 2. But if you do not have any layout file like application.rhtml or application.html.erb then you may also choose to put "javascript_include_tag :defaults" line directly on index.html.erb or index.rhtml file under your app/views/readings/index.html.erb or ...index.rhtml. 3. Now we are talking about ReadingsController index action with a list of all locations displayed on it in a div with id say - < div id="reading_list_div" > You need one more action which will be take one argument as selected state and will populate a new list of locations which are related to THAT PARTICULAR state and render the new list of locations via AJAX on the same index page. 4. <%= f.collection_select :state,Station.find(:all,:group => "state",:order =>"state"), :id, :name, {:include_blank =>"None", :onclick => remote_function(:url =>"/reading/show_readings_for_state", :with => "'state_id='+this.value+'") } %> This collection select will trigger an AJAX call to your ReadingsController class for a action named - "show_readings_for_state" which you should define in the controller as, def show_readings_for_state @readings = Reading.find_all_by_state_id(params[:state_id]) respond_to do |format| format.js # this will not redirect the page but will look for javascript template named ("show_readings_for_state.rjs" inside the folder "/app/views/readings/") to execute once #...@readings variable is initialized. end #End of respond_to do block end #End of action show_readings_for_state 5. Now you will need a partial file to replace old list of readings say _readings_list.html.erb inside "app/views/readings/_readings_list.html.erb" 6. And finally the rjs template which will be automatically called after variables in show_readings_for_state action are initialized.. File could be - "show_readings_for_state.rjs" inside the folder "/app/views/readings/" page.replace_html :reading_list_div, :partial=>'readings_list' , :object=>@readings page.visual_effect :highlight, 'reading_list_div' Maybe this will help you. Nitin. On Wed, Mar 3, 2010 at 4:20 PM, Veena Jose <[email protected]> wrote: > > Hai nitin, > > What you think is correct.Now i am getting alllocations irrespective of > state selected pre-displayed on index page. > > I want to display only those "districts" which are part of SELECTED > state in collection_select after AJAX operation > Please help 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]<rubyonrails-talk%[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.

