我正在尝试使用money gem在我的应用程序中处理货币,但我遇到了一个奇怪的错误.这就是我在"记录"模型中的含义:
composed_of :amount,
:class_name => "Money",
:mapping => [%w(cents cents), %w(currency currency_as_string)],
:constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) },
:converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") }
Run Code Online (Sandbox Code Playgroud)
amount是一个整数.
当我创建一个新记录时,它会忽略我在amount字段中输入的任何值,并将其默认为0.我需要在表单中添加一些内容吗?
我使用的是rails 3.0.3,而money gem版本是3.5.5