# Bug in Firebug or in RJS? Or something else?

**URL:** <https://www.ruby-forum.com/t/bug-in-firebug-or-in-rjs-or-something-else/96256>\
**Category:** Rails\
**Created:** [June 27, 2006, 7:21pm UTC](https://www.ruby-forum.com/t/bug-in-firebug-or-in-rjs-or-something-else/96256 "2006-06-27T19:21:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [June 27, 2006, 7:21pm UTC](https://www.ruby-forum.com/t/bug-in-firebug-or-in-rjs-or-something-else/96256/1 "2006-06-27T19:21:26Z")

</div>

I’m getting a really strange result using RJS page.replace\_html and  
wonder if anybody knows anything that could help me figure it out.

I’m rendering a partial in a loop in edit.rhtml that puts a set of

s on the page, each 
 containing a checkbox\_tag with an associated observe\_field and a text\_field\_tag also with an associated observe\_field. When the checkbox changes the observe\_field shoots an AJAX message back to the controller which, when it's finished doing its database-update thing, does a render :update do |page| page.replace\_html ... which is \_supposed to\_ \*replace\* the content of the 
 from which it was called. Unfortunately, that's not what's happening.

As viewed in Firebug, the page.replace\_html is _adding_ the partial to  
the content of the

, not _replacing_ the content. When I do a page  
reload, the 
s on the page get re-rendered from edit.rhtml and  
everything’s back to where it should be, until I do a render :update  
from the controller again.

I tried to check it out in IE, but IE won’t respond to the RJS at all  
for some reason. Maybe that’s a clue.

Anybody got any ideas on what I could be doing wrong or how I might  
figure it out?

TIA,  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [June 27, 2006, 8:55pm UTC](https://www.ruby-forum.com/t/bug-in-firebug-or-in-rjs-or-something-else/96256/2 "2006-06-27T20:55:15Z")

</div>

Bill W. wrote:

> I’m getting a really strange result using RJS page.replace\_html and  
> wonder if anybody knows anything that could help me figure it out.
> 
> I’m rendering a partial in a loop in edit.rhtml that puts a set of
> 
> s on the page, each 
> containing a checkbox\_tag with an associated observe\_field and a text\_field\_tag also with an associated observe\_field. When the checkbox changes the observe\_field shoots an AJAX message back to the controller which, when it's finished doing its database-update thing, does a render :update do |page| page.replace\_html ... which is \_supposed to\_ \*replace\* the content of the 
> from which it was called. Unfortunately, that's not what's happening.
> 
> As viewed in Firebug, the page.replace\_html is _adding_ the partial to  
> the content of the
> 
> , not _replacing_ the content. When I do a page  
> reload, the 
> s on the page get re-rendered from edit.rhtml and  
> everything’s back to where it should be, until I do a render :update  
> from the controller again.
> 
> I tried to check it out in IE, but IE won’t respond to the RJS at all  
> for some reason. Maybe that’s a clue.
> 
> Anybody got any ideas on what I could be doing wrong or how I might  
> figure it out?
> 
> TIA,  
> Bill
> 
> What javascript is being generated? Looking at that might help you  
> figure out what is happening since the problem is most liekly in the RJS  
> -\> JS translation.

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [June 27, 2006, 9:59pm UTC](https://www.ruby-forum.com/t/bug-in-firebug-or-in-rjs-or-something-else/96256/3 "2006-06-27T21:59:48Z")

</div>

Hi Alex,

Alex W. wrote:

> What javascript is being generated? Looking at that might help you  
> figure out what is happening since the problem is most liekly in the RJS  
> -\> JS translation.

I’ve looked at the javascript and it’s correct. I’m beginning to think  
the  
problem is that the checkbox\_tag names (there are a bunch of checkboxes  
on  
the page) are all the same. I can check and uncheck the first checkbox  
on  
the page as many times as I want and everything is hunky-dory. Any of  
the  
checkboxes below that exhibit the same behavior, independent of their  
original state:

1. change state -\> POSTs to the controller action, response received and

 is updated 2) change state -\> POSTs to the controller action, response received and
 is updated 3) change state -\> no POST to the controller action

I’m thinking that maybe the observe\_field looses track of what it’s  
observing. If I go to the checkbox on the top of the page and change  
ITs  
state after the three steps above, the POST that didn’t happen in step  
3)  
DOES happen and THAT

 gets updated _along_ with the one at the top!

So I think I need to give the checkboxes unique names. Problem is, I  
can’t  
figure out how to do that in the partial. Or rather, I can give the  
checkbox a unique name with a passed-in local, but the observe\_field  
just  
throw-up all over it with “Form.Element.Serializers[method] is not a  
function” messages.

Here’s the partial —

 \> \<%= display\_name %\> \<%= check\_box\_tag(illness\_name, numeric\_value, checked\_value) %\> \<%= observe\_field(illness\_name, :url =\> {:action =\> 'update\_std', :id =\> illness\_name}) %\>

\<% if date\_exists == ‘true’ %\>  
Approx. Date:  
\<%= text\_field\_tag(‘date’, illness\_date, :size =\> 30) %\>  
\<%= observe\_field(‘date’, :url =\> {:action =\> ‘update\_date’, :id =\>  
illness\_name}, :with =\> “idate” ) %\>  
\<% end %\>

illness\_name, numeric\_value, and checked\_value are all passed in as  
locals.  
The “:id=\>illness\_name” doesn’t give observe\_field any heartburn. But  
using  
it in the ‘name’ field doesn’t work. In addition to the above, I’ve  
tried:

1. \<%= observe\_field(%Q{illness\_name},… --\> element has no properties
2. \<%= observe\_field(%Q{#{illness\_name}},… --\>  
Form.Element.Serializers[method] is not a function
3. \<%= observe\_field(%q{illness\_name},… --\> element has no properties
4. \<%= observe\_field(%q{#{illness\_name}},… --\> element has no  
properties
5. \<%= observe\_field(#{illness\_name},… --\> compile error for syntax  
error  
on the following line (i.e., can’t parse {} in that location)

I’m out of ideas. You got any? Anybody else?

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [September 23, 2009, 12:11am UTC](https://www.ruby-forum.com/t/bug-in-firebug-or-in-rjs-or-something-else/96256/4 "2009-09-23T00:11:18Z")

</div>

Even though you prob don’t care anymore, I had this problem and wanted  
to post in case anyone had the same problem.

Try ‘page.replace’ not ‘page.replace\_html’.

I guess replace\_html is short for replace “inner” html, as that is what  
it does if you look up the documentation. I was debugging using  
netbeans and stepped into the replace\_html method and that is what the  
nice comments said.
