# Observe\_form + Check\_box = call action? I need help

**URL:** <https://www.ruby-forum.com/t/observe-form-check-box-call-action-i-need-help/125122>\
**Category:** Rails\
**Created:** [January 5, 2008, 8:02pm UTC](https://www.ruby-forum.com/t/observe-form-check-box-call-action-i-need-help/125122 "2008-01-05T20:02:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mel\_ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecccb3/32.png) [@mel\_ram](https://www.ruby-forum.com/u/mel_ram)\
**Post date:** [January 5, 2008, 8:02pm UTC](https://www.ruby-forum.com/t/observe-form-check-box-call-action-i-need-help/125122/1 "2008-01-05T20:02:59Z")

</div>

What I am trying to do is create partial that will be invoked by  
a :show\_product action under the :admin controller.

This partial is meant to have a list of categories and checkboxes next  
to each category. I want to set it up so when someone checks/unchecks  
a category, it does something like category.products \< self

The models for both Category and Product have a hmabt relationship w/  
each other.

The code I’ve got so far is:

* * *

# show\_product.rhtml

\<%= render :partial =\> “categories”, :product =\> @product %\>

# \_categories.rhtml

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

 \<% form\_for :category, category, :url =\> { :action =\> "update\_product\_category" }, :id =\> category.id do |f| %\> \<%= f.check\_box :name %\>\<%= f.label category.name %\> \<% end %\> 
 \<% end %\>   
  
\<% else %\> 

No categories found.

\<% end %\>
# admin\_controller.rb

def categories  
@categories = Category.find(:all)  
end

* * *

The output from currently is:

 Men 

QUESTIONS:

- How do I set up an observe\_form or observe\_field so that if someone  
clicks on the a checkbox, it calls the action :update\_product\_category  
and passes it the parameter of @product.id and category.id?
- Why does the check\_box code also produce a hidden field? If I remove  
the check\_box code, it doesn’t produce the hidden field any more.
- What’s up with the authenticity\_token?

---

<div class="post-metadata">

**Author:** ![mel\_ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecccb3/32.png) [@mel\_ram](https://www.ruby-forum.com/u/mel_ram)\
**Post date:** [January 25, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/observe-form-check-box-call-action-i-need-help/125122/2 "2008-01-25T22:27:09Z")

</div>

On Jan 5, 7:50 pm, mel ram [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> - Why does thecheck\_boxcode also produce a hidden field? If I remove  
> thecheck\_boxcode, it doesn’t produce the hidden field any more.

> **[ActionView::Helpers::FormHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000928)**
>
> Form helpers are designed to make working with resources much easier compared to using vanilla HTML.
