Topic: Observe field to render partial

I have a select list that has 3 static choices and would like to use ajax to render a different partial when a choice is selected without the user having to hit submit.  What is the best way to do this?

Thanks!

Last edited by gipper05 (2009-01-20 15:06:35)

Re: Observe field to render partial

<%= observe_field "id_of_select_tag", :url => your_desired_url(), 
                                      :update => "name_of_div_to_insert_partial",
                                      :with => "'selected='+value"
%>
# keep in mind to put this code AFTER the select tag, not before it

#controller:
def action_that_was_called_by_observe_field
  render :partial => params[:selected]
  #assuming you have partials named after the values in the select
end

Re: Observe field to render partial

Thank you for posting this! Your consice example has helped me immensely.