black_star 发表于 2013-1-23 02:21:34

ruby on rails(9) -

高亮价格变化。首先保存我们当前的购物车。在models/cart.rb编辑add_product.
def add_product(product)current_item = @items.find{|item| item.product == product}if current_item current_item.increment_quantityelseurrent_item = CartItem.new(product)@items << current_item   endcurrent_item#返回当前购物车,这样也可以,return也不用?end
编辑 store_controller.rb
@cart = find_cart @current_item = @cart.add_product(product) #获取当期购物车 respond_to{|format| format.js}

编辑_cart_item partial,判断当前购物车是否是我们改变的那个
<%if cart_item == @current_item%><tr id="current_item"><% else %><tr><% end %>

编辑 add_to_cart.js.rjs 添加效果
page[:current_item].visual_effect :highlight,:startcolor => "#88ff88",:endcolor => "#ff0000"
用page[:current_item]产生js对象,visual_effect 插件,视觉效果,hightlight
高亮。可看到点击add_to_cart时,价格颜色会渐变
页: [1]
查看完整版本: ruby on rails(9) -