# Observe\_field - returning weird key/value pair

**URL:** <https://www.ruby-forum.com/t/observe-field-returning-weird-key-value-pair/168082>\
**Category:** Rails\
**Created:** [May 15, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/observe-field-returning-weird-key-value-pair/168082 "2009-05-15T16:18:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [May 15, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/observe-field-returning-weird-key-value-pair/168082/1 "2009-05-15T16:18:03Z")

</div>

i am currently having a very strange problem with observe\_field.

i have a select box that looks like this:

> \<%= select “product\_section”, “section”, ProductSection.find(:all, :order =\> “title ASC”).collect { |p| [p.title, p.id]}, { :include\_blank =\> true } %\>

i want to observe the drop down box to have an action happen whenever  
the value of the dropdown is changed…

i have added the following code to observe the field:

\<%= observe\_field(:product\_section\_section, :update =\> ‘attribute\_data’,  
:url =\> ‘insert\_attributes’, :frequency =\> 1) %\>

notice the naming of the field\_id in observe field. this does work…

the problem is, when i make a selection, the parameters that get passed  
look like this:

params = {“7”=\>nil,  
“authenticity\_token”=\>“f245fed70e1760739566121d68a8340a154e086a”,  
“action”=\>“insert\_attributes”, “controller”=\>“admin”}

that key/value of “7”=\>nil is the one i am interested in… but it seems  
like it’s backward. i am thinking i should get a key/value passed that  
looks more like:

‘“product\_section”=\>“7”’

anyone have any idea what i am doing wrong?

thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [May 15, 2009, 4:34pm UTC](https://www.ruby-forum.com/t/observe-field-returning-weird-key-value-pair/168082/2 "2009-05-15T16:34:58Z")

</div>

just as a hint…

when i submit this form, the select box value looks like this:

“product\_section”=\>{“product\_section\_id”=\>“3”}

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [May 15, 2009, 10:33pm UTC](https://www.ruby-forum.com/t/observe-field-returning-weird-key-value-pair/168082/3 "2009-05-15T22:33:31Z")

</div>

You can omit frequency if u just want to trigger on change. To pass  
arbitrary parameters use the :with option like described in the rails  
api for link\_to\_remote. I would be more specific if i weren’t on my  
cell in berlin underground 🙂

2009/5/15, Sergio R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> the value of the dropdown is changed…  
> the problem is, when i make a selection, the parameters that get passed
> 
> ‘“product\_section”=\>“7”’
> 
> anyone have any idea what i am doing wrong?
> 
> ## thanks!
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Von meinen Mobilgerät aus gesendet

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [May 16, 2009, 12:28am UTC](https://www.ruby-forum.com/t/observe-field-returning-weird-key-value-pair/168082/4 "2009-05-16T00:28:26Z")

</div>

Sergio,

show me the generated html of select and observer…

t

Sergio R. wrote:

> params = {“7”=\>nil,  
> anyone have any idea what i am doing wrong?
> 
> thanks!

# –

Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

- experienced RoR/PHP freelancer, available for hire

# [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz
