I'm having some serious trouble understanding what's going on with my
I am creating a manager for tree structures with drag-and-drop
functionality and such. It's very generic, so it makes no assumptions
about the objects it works on (apart from the existence of ids and
parent_ids in the objects). It sort of wraps around partials that are
specific to the models that go in the tree, one partial for viewing,
and one for when you're creating new model instances inside the tree.
That means I have a create link on nodes (that are saved and thus have
an id) that creates a preset child node of the current node by
assigning the current node's id value to the child node id, then
renders the forementioned partial that is used to edit the actual data
fields of the object in the node.
Because I want a generic approach, I don't want to make any
assumptions about how these partials are implemented, and I tried to
put as little demand as possible on what they needed to be able to do.
So far, the only thing I absolutely need to know ("I" being the tree,
or more precisely, the parent node of the soon-to-be child node that
has just been rendered after the user clicked the "create new child
node of this node" link) is when the child node's editor has saved the
new child node successfully. I need to know that, so that I can add,
e.g. a "create new child node" link to the child node that has just
ajax anyway, so existing nodes stay pretty much the same
"internally" (inside their surrounding divs) even if new leaf nodes
are added or nodes are moved around.
So, I thought that for new nodes, I'd generate and pass on a
partial after it had saved the node successfully and thus caused it to
have a unique id, and be allowed to have its own child nodes.
However, and this is where it gets weird, I cannot seem to get any
as a response to an ajax request, like link_to_remote, or
Put simply, if I refresh my page, as in a regular GET html request,
this causes the root nodes to be drawn in a "standard" way
(index.rhtml iterates over nodes, and renders the partial 'tree_node'
for each), then I can inspect the DOM in firebug and confirm that all
script portions of the partial view are rendered correctly, e.g.
This not only alerts 'hello', the script tags and contents are also
visible in firebug.
But, if I then expand one of these root node, which means triggering a
link_to_remote that causes the exact same view partial to be rendered
into a "children" div, the scripts "disappear". Depending on where I
put the scripts in the partial, I might get an alert box greeting me,
but the script is nowhere to be found in firebug regardless. And, if I
actually define a callback and try to call it, either from a nested
partial, or by typing it into the address line of the browser, I
simply get the response that it isn't defined...
I am totally stomped!
Please, please, someone help me find out what's going on here... I'm
frustrated beyond what's healthy.
Cheers and thanks in advance for any pointers,