2
我有以下模型JobRequest :: Receipt。如何更新Rails模型中的BigDecimal屬性?
The amount的屬性是一個很大的數字,你可以看到。
# Table name: job_request_line_headers
#
# id :integer not null, primary key
# type :string(255)
# job_request_id :integer
# merchant_company_id :integer
# merchant_id :integer
# default_setting :boolean default(FALSE)
# payment_amount :decimal(12, 4)
# payment_state :integer default(0)
# payment_at :datetime
# deleted_at :datetime
# published_at :datetime
# delivered_at :datetime
# created_at :datetime
# updated_at :datetime
# related_line_header_id :integer
# amount :decimal(12, 4)
這是對象是什麼樣子
> JobRequest::Receipt id: 24, type: "JobRequest::Receipt",
> job_request_id: 19, merchant_company_id: nil, merchant_id: nil,
> default_setting: false, payment_amount: nil, payment_state: 1,
> payment_at: nil, deleted_at: nil, published_at: nil, delivered_at:
> nil, created_at: "2016-03-07 06:58:49", updated_at: "2016-03-07
> 06:58:49", related_line_header_id: nil, amount:
> #<BigDecimal:7ffe424c7d48,'0.0',9(18)
如果我嘗試更新任何它下面的方法將提交SQL量屬性,但它會不會更新值
撬(主)> JobRequest :: Receipt.last.update_attribute(:量,22.3)
撬(主)> JobRequest :: Receipt.last.update_attribute(:量,BigDecimal.new(22.3,5 )
量= BigDecimal.new(22.3,5)
撬(主)> JobRequest :: Receipt.last.update_attribute(:量,量)
任何那些將返回量設置爲零。
> [86] pry(main)> JobRequest::Receipt.last.amount
JobRequest::Receipt
> Load (1.7ms) SELECT "job_request_line_headers".* FROM
> "job_request_line_headers" WHERE
> "job_request_line_headers"."deleted_at" IS NULL AND
> "job_request_line_headers"."type" IN ('JobRequest::Receipt') AND
> "job_request_line_headers"."default_setting" = 'f' ORDER BY
> "job_request_line_headers"."id" DESC LIMIT 1
> => #<BigDecimal:7ffe3be9bc40,'0.0',9(18)>
任何線索我做錯了什麼?