Topic: visaul_effect on dynamic (AJAX-created) element

What's the cleanest way to apply a visual_effect to an element as it's created? For example, assume I have the standard AJAX demo -- an unordered list where list elements are created and appended to the list items:

form_remote_tag( :url => { :action => 'create' },
   :update => 'my_list',
   :position => 'bottom',
   :success => ...

In :success I could apply e.g. a visual_effect(:highlight, my_list), but I can't find any solid examples of a way to apply the effect to the new element only (ul.my_list li) as opposed to the whole of ul.my_list. Any thoughts?

Re: visaul_effect on dynamic (AJAX-created) element

You can do this with RJS:

# in views/my_controller/create.rjs file
page.insert_html :bottom, :my_list, :partial => 'item'
page[:new_list_item].visual_effect :highlight

If you don't render anything in your create action, this RJS file should end up being called. Of course, you'll need to replace new_list_item, etc. with whatever you are using.

With RJS, the form remote tag would just be:

form_remote_tag :url => { :action => 'create' }

Railscasts - Free Ruby on Rails Screencasts