Forum: Ruby on Rails Odd behavior from the respectable replace_html and his lovel

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
75cb325d7b55a6659fc050f6fa822c7c?d=identicon&s=25 Andrei (Guest)
on 2007-07-17 02:47
(Received via mailing list)
Hello there, kind RoR folk. I have a wee bit of a pickle, so i'll get
straight to the point.

In one of my views i have two matching dropdowns containing teams.
Upon the changing of the selection, provided that the two are
different, my desire is to spawn another dropdown containing referees.
Below is the view code for one of the dropdowns. The other one is
strikingly similar.

<%= form.collection_select "first_team_id", @teams, :id, :name, {}, {
  :onchange => remote_function(   :update => "referees",
                                  :url => { :action =>
"update_referees" },
                                  :with => "'match[first_team_id]=' +
this.value + '&match[second_team_id]=' + $
                                  :condition => "this.value != $
  }  %>

The dropdown is contained in a partial aptly named "referees", and as
to my best knowledge, i have populated a rjs file associated to the
'update_referees' action with the following:

page[:referees].replace_html :partial => "referees"

This, however, fails to produce the expected result and instead just
spews the javascript inside my lovely 'referees' layer. However, being
a persistent individual, i altered the .rjs to

page[:referees].replace :partial => "referees"

Unexpectedly, this does actually produce a dropdown, but unfortunately
also destroys my layer and with it any hope i would have to rebuild my
dropdown in case the team selection is altered.

After some hours of scraping through documentation and debugging
prototype i noticed that Ajax.Updater actually runs through the code
twice, first upon receiving it, and subsequently within the
"updateContent" method. Sadly, however, on the first run of the code
everything is left in order and fully peachy, but after the
"updateContent" method, my previously cheery layer is filled with

If you've made it thus far, first of all i'd like to thank you for
being so patient, and second i would like to ask whether i am doing
something that i'm not supposed to or prototype is goofing.

Many thanks,
This topic is locked and can not be replied to.