Can you not add the code in your display_cart view? Just put something like <%= visual_effect :highlight, 'cart_item_'[EMAIL PROTECTED] %> in the display_cart template (maybe add some logic to only perform the effect if it's a xhr request) and since rendering of that view is essentially going to happen when the request is complete it should accomplish the same thing no?
Just my quick thoughts. Maybe I'm missing something. :) On 1/10/06, Dave Thomas <[EMAIL PROTECTED]> wrote: > Mike and I demo an Ajaxified version of the Depot application in the > Rails Studio. Part of the demo is a cart in the sidebar which updates > when you add a product to it. As well as updating the div, it also > highlights the most recently added link item. Right now, we do it with: > > <script language="JavaScript"> > function flash_cart(request) { > var id = request.getResponseHeader('X-Item-Id'); > new Effect.Highlight('cart_item_' + id, > { startcolor: "#66bb66", > endcolor: "#114411" }); > } > </script> > > <%= link_to_remote 'Add to Cart', > :url => {:action => 'add_to_cart', :id => product}, > :update => 'cart', > :complete => 'flash_cart(request)' > %> > > The controlled sends down item_id as a header when the object gets > added: > > def add_to_cart > product = Product.find(params[:id]) > item = @cart.add_product(product) > if request.xhr? > headers['X-Item-Id'] = item.object_id > render(:action => "display_cart", :layout => false) > else > redirect_to(:action => 'index') > end > end > > > I'd really like to use visual_effect() instead of having my own > flash_cart method, but I can't think of a way of giving it the > element ID dynamically. Am I missing something? > > > Cheers > > > Dave > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs