ruby on rails(9) -- AJAX(2)
価格の変化をハイライトします.まず、現在のショッピングカートを保存します.モデル/cart.rb add_の編集product.
store_の編集controller.rb
編集_cart_item partial、現在のショッピングカートが私たちが変えたものかどうかを判断します.
add_の編集to_cart.js.rjs追加効果
page[:current_item]でjsオブジェクトを生成し、visual_effectプラグイン、ビジュアルエフェクト、hightlight
ハイライトクリックadd_が表示されますto_cartの場合、価格の色がグラデーションになります
def add_product(product)
current_item = @items.find{|item| item.product == product}
if current_item
current_item.increment_quantity
else
urrent_item = CartItem.new(product)
@items << current_item
end
current_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の場合、価格の色がグラデーションになります