class CartItemsController < ApplicationController
before_filter :initialize_cart, :check_not_signedin
def create
product = Product.find(params[:product_id])
kart = initialize_cart
qty = CartItem.select(:quantity).where(:cart_id => kart.id, :product_id => product.id)
if qty == 0
@item = CartItem.new(:cart_id => kart.id, :product_id => product.id, :quantity => qty+1)
if @item.save
flash[:success] = "Product added"
redirect_to category_products_path
end
else
if CartItem.where("cart_id = ? AND product_id = ?", kart.id, product.id).first.update_column(:quantity, qty+1)
flash[:success] = "Product updated"
redirect_to category_products_path
end
end
end
当我尝试运行它时,我收到以下错误“无法将 FixNum 转换为数组”app/controllers/cart_items_controller.rb:17:in `create'
请帮忙!