# Problems with Rails 1.1 observe\_field :with serialized

**URL:** <https://www.ruby-forum.com/t/problems-with-rails-1-1-observe-field-with-serialized/56699>\
**Category:** Rails\
**Created:** [April 3, 2006, 2:28am UTC](https://www.ruby-forum.com/t/problems-with-rails-1-1-observe-field-with-serialized/56699 "2006-04-03T02:28:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![asa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@asa](https://www.ruby-forum.com/u/asa)\
**Post date:** [April 3, 2006, 2:28am UTC](https://www.ruby-forum.com/t/problems-with-rails-1-1-observe-field-with-serialized/56699/1 "2006-04-03T02:28:32Z")

</div>

I’d like to use observe\_field to watch a field, and then when it changes  
send the entire form to the server. I had been using

\<%= observe\_field 'entity\_name\_'removed\_email\_address@domain.invalid\_s, :frequency =\> 0.5,  
:update =\> 'auto\_complete\_'removed\_email\_address@domain.invalid\_s, :url =\>  
{ :controller =\> ‘committees’, :action=\>  
‘auto\_complete\_for\_entity\_name’,:params=\>{:committee\_id=\>@committee.id}  
}, :with =\> ‘Form.serialize(“new\_contrib\_form\_#{@account.id.to\_s}”)’ %\>

But the problem appears to be that when this is made into Javascript, it  
wants to do something like

parameters:‘Form.serialize(‘search\_form’)=’+value

It used to work fine and give me

parameters:Form.serialize(‘search\_form’)

I’m pretty sure the same thing happens with observe\_form. Ideas?

Thanks,  
Asa

---

<div class="post-metadata">

**Author:** ![asa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@asa](https://www.ruby-forum.com/u/asa)\
**Post date:** [April 3, 2006, 12:15pm UTC](https://www.ruby-forum.com/t/problems-with-rails-1-1-observe-field-with-serialized/56699/2 "2006-04-03T12:15:17Z")

</div>

Asa H. wrote:

> wants to do something like  
> Asa

Asa,

It seemed to work for me after I removed the quotes from the form being  
observed.  
I changed from  
Form.serialize(‘form\_name’)  
to  
Form.serialize(form\_name)  
and it worked again as before…

Daniel

---

<div class="post-metadata">

**Author:** ![asa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@asa](https://www.ruby-forum.com/u/asa)\
**Post date:** [April 3, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/problems-with-rails-1-1-observe-field-with-serialized/56699/3 "2006-04-03T17:20:07Z")

</div>

That doesn’t work for me. What happens is that the parameters passed  
look like

Parameters: {“Form.serialize(new\_contrib\_form\_13)”=\>“A”,  
“action”=\>“auto\_complete\_for\_entity\_name”, “controller”=\>“committees”,  
“committee\_id”=\>“1”}

The relevant (new for 1.1) section of the API says:

:with: A JavaScript expression specifying the parameters for the  
XMLHttpRequest. This defaults to â??valueâ??, which in the evaluated context  
refers to the new field value. If you specify a string without a “=”,  
itâ??ll be extended to mean the form key that the value should be assigned  
to. So :with =\> “term” gives “â??termâ??=value”. If a “=” is present, no  
extension will happen.

The problem is in the adding of the equals sign, etc. It’s trying to do  
too much work for me.

Asa

daniel wiesmann wrote:

> Asa H. wrote:
> 
> > wants to do something like  
> > Asa
> 
> Asa,
> 
> It seemed to work for me after I removed the quotes from the form being  
> observed.  
> I changed from  
> Form.serialize(‘form\_name’)  
> to  
> Form.serialize(form\_name)  
> and it worked again as before…
> 
> Daniel

---

<div class="post-metadata">

**Author:** ![asa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@asa](https://www.ruby-forum.com/u/asa)\
**Post date:** [April 3, 2006, 7:43pm UTC](https://www.ruby-forum.com/t/problems-with-rails-1-1-observe-field-with-serialized/56699/4 "2006-04-03T19:43:25Z")

</div>

OK. I seem to have gotten it working again, but the solution seems like  
a total hack.

:with =\> “foo = Form.serialize(‘new\_contrib\_form\_#{@account.id.to\_s}’)”

Including the = sign in the :with tag prevents it from rewriting with  
‘=value’ at the end. However, the “foo =” part doesn’t matter at all,  
except that it’s a valid statement. I see nothing about anything called  
“foo” on the Rails side. I do, however, get the whole form into  
params[] as I would like. So, it works, but feels shaky.

Asa

Asa H. wrote:

> That doesn’t work for me. What happens is that the parameters passed  
> look like
> 
> Parameters: {“Form.serialize(new\_contrib\_form\_13)”=\>“A”,  
> “action”=\>“auto\_complete\_for\_entity\_name”, “controller”=\>“committees”,  
> “committee\_id”=\>“1”}
> 
> The relevant (new for 1.1) section of the API says:
> 
> :with: A JavaScript expression specifying the parameters for the  
> XMLHttpRequest. This defaults to â??valueâ??, which in the evaluated context  
> refers to the new field value. If you specify a string without a “=”,  
> itâ??ll be extended to mean the form key that the value should be assigned  
> to. So :with =\> “term” gives “â??termâ??=value”. If a “=” is present, no  
> extension will happen.
> 
> The problem is in the adding of the equals sign, etc. It’s trying to do  
> too much work for me.
> 
> Asa
> 
> daniel wiesmann wrote:
> 
> > Asa H. wrote:
> > 
> > > wants to do something like  
> > > Asa
> > 
> > Asa,
> > 
> > It seemed to work for me after I removed the quotes from the form being  
> > observed.  
> > I changed from  
> > Form.serialize(‘form\_name’)  
> > to  
> > Form.serialize(form\_name)  
> > and it worked again as before…
> > 
> > Daniel

---

<div class="post-metadata">

**Author:** ![asa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@asa](https://www.ruby-forum.com/u/asa)\
**Post date:** [April 4, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/problems-with-rails-1-1-observe-field-with-serialized/56699/5 "2006-04-04T15:38:51Z")

</div>

yep, I can confirm the same thing is happening with observe\_form in my  
app and your work around fixes it.

But would be nice to not have to do that I suppose.

---

<div class="post-metadata">

**Author:** ![asa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@asa](https://www.ruby-forum.com/u/asa)\
**Post date:** [April 4, 2006, 5:33pm UTC](https://www.ruby-forum.com/t/problems-with-rails-1-1-observe-field-with-serialized/56699/6 "2006-04-04T17:33:15Z")

</div>

observe\_form apparently defaults to sending the whole form, so for it  
you can just leave off :with completely, and it’ll work.

Asa

Andy Shen wrote:

> yep, I can confirm the same thing is happening with observe\_form in my  
> app and your work around fixes it.
> 
> But would be nice to not have to do that I suppose.

---

<div class="post-metadata">

**Author:** ![asa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/dfb087/32.png) [@asa](https://www.ruby-forum.com/u/asa)\
**Post date:** [April 5, 2006, 7:23pm UTC](https://www.ruby-forum.com/t/problems-with-rails-1-1-observe-field-with-serialized/56699/7 "2006-04-05T19:23:04Z")

</div>

hi there.  
i had the same problem in an app where one dev used observe\_fields  
(little code snippet from the rails wiki)  
the workaround didn´t work for me so i went ahead and just changed the  
source of the prototype\_helper and took out the part where it adds the =

- value stuff.  
its in  
gems/actionpack-1.12.0/lib/action\_view/helpers/prototype\_helper.rb  
in the function build\_observer  
just thought i´d mention that as another quick fix.  
kind regards,  
a
