# How to get Observer fields watching checkboxes

**URL:** <https://www.ruby-forum.com/t/how-to-get-observer-fields-watching-checkboxes/75186>\
**Category:** Rails\
**Created:** [November 8, 2006, 2:11am UTC](https://www.ruby-forum.com/t/how-to-get-observer-fields-watching-checkboxes/75186 "2006-11-08T02:11:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [November 8, 2006, 2:11am UTC](https://www.ruby-forum.com/t/how-to-get-observer-fields-watching-checkboxes/75186/1 "2006-11-08T02:11:30Z")

</div>

Imagine the classic department, employee relation construct (Employees,  
Departments tables)

A department can have a number of employees, employees must belong to  
one department, there are many departments)

I have two divs one contains a number of check boxes with the various  
departments

London [x] LA [x] Paris [x] Sydney [x] Tokyo [x] Rome [x] New York [x] Bangalore [x]

Bob | London Remy | Paris Chuck | New York Jen | Rome Ken | Tokyo Paul | London

The number of departments are variable and can change over time, so  
“hard” coding observers are impossible

—Controller—

@departments = Department.find(:all)

—View-----  
\<% for dept in @departments

 \<%= dept.dname \<% check\_box\_name = "dept[" + dept.id.to\_s + "][query]" %\> \<%= check\_box\_tag ( check\_box\_name,dept.id.to\_s, :checked =\> true ) %\> \<%= observe\_field (check\_box\_name, :frequency =\> 0.5, :update =\> :employee\_list , :url =\> { :action =\> :filter\_depart}, :with =\> "'exclude=' + escape(" + dept.id.to\_s + ") + '&checked=' + escape(value)" ) %\>
* * *

This actually works well when the users clicks (unchecks or checks) on  
the check box of a department the controller action “filter\_depart” is  
called and by checking the parameter of “exclude” and the value of  
“checked” it is possible to determine wich dept id was checked or  
unchecked and the query to employee table can be filtered on this info.

In the example above if the user unchecks London, Bob and Paul will  
disappear from the employee listing. Happy ROR and AJAX developer.

The problem is that if the user then unchecks another check box eg.  
Rome, the filter\_depart controller action is called and Rome, Jen is  
removed. However London ( Bob and Paul) employees are retrived even if  
Londons check box remains unchecked.

The reason is that the controller action filter\_depart is called by the  
observer upon the change of a single check box and the value parameters  
exclude and checked apply only to that single check box rather than the  
array of check boxes.

Is there anyway to have an observer field(s) notice any change to any  
field(s) particularly those generated with the standard check\_box\_tag  
processing and lauch a “submit\_to\_remote” , which will mean that all  
params of the form (including all check boxes values) are available to a  
given controller?

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [November 8, 2006, 2:15am UTC](https://www.ruby-forum.com/t/how-to-get-observer-fields-watching-checkboxes/75186/2 "2006-11-08T02:15:56Z")

</div>

Is observe\_form the correct way to go with this?
