UJS bug? Defect?

Has anyone here had any experience using the ujs4rails plugin? I am
encountering an issue where reloading working apply_behavior instances
via ajax breaks them silently–causing the form in question to be
submitted without js, reloading the page, and thus enabling the ajax
again. Apparently this is an issue with how UJS caches the JS, but is
there an available option I am missing that accounts for this? Thanks,

Floyd

Hi Floyd, I’m not quite sure I follow what you mean. Could you give a
more concrete example?

Cheers
Luke

Ok, here is my specific set up:

I’ve got a form for a model A and inside the form is a partial containg
fields for an associated model B. Initially two sets of fields for B
are loaded with the page, but the user can remove or add more fieldsets
dynamically using button inputs. This is where I’ve implemented UJS:

    <% unless author.eql? @authors.first %>
      <%= content_tag "button", "Remove this author", :type =>

“submit”, :id => “remove-author-#{index}”, :name => “remove_author”,
:value => index %>
<% apply_behavior “#remove-author-#{index}:click”,
remote_function(:url => {:action => :remove_author, :remove => index},
:update => “revision_authors”, :submit => “revision_authors”),
:prevent_default => true %>
<% end %>
<% if author.eql? @authors.last %>
<%= content_tag “button”, “Add another author”, :type =>
“submit”, :id => “add-author-#{index}”, :name => “add_author” %>
<% apply_behavior “#add-author-#{index}:click”,
remote_function(:url => {:action => :add_author}, :update =>
“revision_authors”, :submit => “revision_authors”), :prevent_default =>
true %>
<% end %>

This works great first time I click either add or remove. The AJAX
kicks in quite niceley and reloads the fields --one set for each
author-- and those two apply_behavior calls. But after the ajax is
complete and a set of fields has either been added or removed, none of
the buttons work with AJAX. Instead they revert to their default
behavior which is to submit the whole form.

Also in case it’s helpful, I inspected the JS for the page before
making the first AJAX request and there was a reference to
/behaviours/action.js, but that file didn’t exist on the server.

I appreciate your attempting to work me through this. Obviously I
don’t fully comprehend how the caching works.

Floyd

Hi Floyd, see my comments on the UJS trac.