Bug in Firebug or in RJS? Or something else?

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

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.

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs