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 <div>s on the page, each <div> 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 <div> 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 <div>, not *replacing* the content. When I do a page reload, the <div>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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060627/aa5393e3/attachment.html
Bill Walton 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 > <div>s on the page, each <div> 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 <div> 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 <div>, not *replacing* the content. When I do a page > reload, the <div>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, > BillWhat 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. -- Posted via http://www.ruby-forum.com/.
Bill Walton
2006-Jun-27 19:58 UTC
[Rails] Re: Bug in Firebug or in RJS? Or something else?
Hi Alex, Alex Wayne 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 <div> is updated 2) change state -> POSTs to the controller action, response received and <div> 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 <div> 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 --- <div id=<%= illness_name %> > <label><%= display_name %></label> <%= 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 %> </div> 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