我正在尝试让money-rails gem 工作,但我遇到了问题......
其他类似的 stackoverflow 问题已有 6 年历史。
这是我有相应列的产品:
class Transactions < ActiveRecord::Base
belongs_to :user, optional: true
validates :trans_id, uniqueness: true
monetize :price_cents
end
我的 Gemfile 中有 gem,并且成功运行了 bundle install。
当我创建一个新项目并用撬来查看它时,
create(vendor:"foo",amount:2.6,trans_id:'123cccc')
id: nil,
vendor: "foo",
amount_cents: 260,
amount_currency: "USD",
trans_id: "123cccc",
tax_cents: 150,
total_cents:410,
- 我如何以美元金额使用它?即我想将amount_cents 添加到tax_cents for total_cents。金额 2.60 而不是 amount_cents: 260,
- 我需要添加“composed_of”吗?
- 另外,为什么命名中是“cent”?我认为它应该被删除,因为模糊的文档指出:
在这种情况下,货币属性的名称是通过从列名称中删除 _cents 后缀自动创建的。