我收到错误“没有将符号隐式转换为整数”
这是我的代码:
# == Schema Information
#
# Table name: my_payments
#
# id :integer not null, primary key
# email :string
# ip :string
# status :string
# fee :decimal(6, 2)
# paypal_id :string
# total :decimal(8, 2)
# created_at :datetime not null
# updated_at :datetime not null
# shopping_cart_id :integer
#
class MyPayment < ActiveRecord::Base
belongs_to :shopping_cart
include AASM
aasm column: "status" do
state :created, initial: true
state :payed
state :failed
event :pay do
after do
shopping_cart.pay!
self.update_stock_products()
end
transitions from: :created, to: :payed
end
end
def update_stock_products
self.shopping_cart.in_shopping_carts.map { |i_sh|
product = i_sh.product
self_product = Product.where(id: product.id)
num = self_product[:stock]
res = num - i_sh.num_products
Product.update(product.id,stock: res)
}
end
end
错误在该行中:
num = self_product[:stock]