Ajax request on page load

For the onload part, just populate a variable in the controller and load the items:

def index     @foos = Foo.find(:all) end

You can then use an observe_field or observe_form in your page to watch the drop down and fire off an ajax call and update the div from your controller using rjs. The docs on observe_field / form are here: http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000535

That should get you pointed in the right direction.

Jean-nicolas Jolivet wrote:

I would put the html in a partial. Remove the :update from your observer_field method and to the update using rjs and a partial from the controller. Here is a mock-up to give you an idea:

def update_list     #gather needed info     @items = Items.find(:conditions.....        #update using rjs     render :update do |page|        page['my-items'].replace_html :partial => 'your_partial'     end end

You should read up a little about rjs, but the basic gist of it is that you can get to any element on your page by using element proxies (page['my-items'] in the above example). One benefit of using rjs is that you can update and change as many items on the page you want, with :update => 'my-items', you are limited to updating one thing on the page per call.

Let me know if you need more help.

-Bill

Jean-nicolas Jolivet wrote: