Using Checkboxes and Ajax to Assign Categories

Hi All,

I have an ‘admin’ controller in which I have a ‘show_product’ action. In
the view of this action, I have a list of names of the categories w/
checkboxes to the left of each.

What I am trying to do is to allow the administrator to just check off
the categories in this show_product view and have it add the product to
the category.

That part I am not able to figure out is how to display the list of
categories & checkboxes and create observe_form’s or observe_field’s to
send the product_id and category_id to the action that will do the logic

Here is the code I’ve got:

@categories & @product is available to the show_product action as


_categories.rhtml (partial gets called into the show_product.rhtml

<% if @categories %>
<% for category in @categories %>

<%= check_box :category_id, :value => %> <%= label :category, :name, %> <%= observe_form, :frequency => 1.0, :update => 'category_notice', :url => { :controller => 'admin', :action => 'update_product_category' }, :with => "'category=' + encodeURIComponent($('').value) + '&product=' + encodeURIComponent($('@product').value)" %>
<% end %>

<% else %>

No categories found.

<% end %>