I’m trying to update a list, and having a hard time applying visual
effects
to the latest element created. Here is what I’m doing.
===========================================
-
Creating an “item” via an action, then rendering the RJS template
-
RJS template looks like this:
page.insert_html :top, ‘items’, :partial => ‘item’
page.visual_effect :highlight, @item_id, :duration => 3
-
Once all this is done, I check the source of the page, and an item
with
the @item_id doesn’t exist in the HTML yet… as it’s just being ajaxed
from
the
partial. If I refresh the page, it’s obviously there.
===========================================
So, my question is… is there a clean way to create an effect on a
newly
created element in a list ?
Most browsers will give you the source of the original request back, not
the source of the current page after ajax magic has happend.
I think that one of the firefox developer plugins can give you the
current source, so you might want to give that a shot.
_Kevin
Dylan S. wrote:
- Once all this is done, I check the source of the page, and an item
with
the @item_id doesn’t exist in the HTML yet… as it’s just being ajaxed
It won’t show via “view source”, since view source will only show the
DOM elements
when page is loaded, now the DOM elements are changed, but view source
won’t
show the change.
Your example normally should work. If it doesn’t work, it could be:
- If the new item is now showing, your partial tempatelate might not be
rendered
right, or the return result from it might break your DOM structure;
- If the new item is added, but highlight is not working, variable
@item_id might
not be defined in the controller corresponding to your rjs
template(not the
one calling the rjs)
-Tony
Kevin O. wrote:
I think that one of the firefox developer plugins can give you the
current source, so you might want to give that a shot.
http://jennifermadden.com/scripts/ViewRenderedSource.html
Thanks guys. Tony, you were right on #1… the DOM was,
ever-so-slightly,
broken
This is a gem. Thank you very much Ben !