我正在尝试使用gem money-rails
但没有成功。
我住在巴西,这里的小数点是“,”,千位分隔符是“。”
因此,我在 money.rb 初始化程序中添加了以下代码:
MoneyRails.configure do |config|
config.default_currency = :brl
config.register_currency = {
:id => :brl,
:priority => 1,
:iso_code => "BRL",
:name => "Real",
:symbol => "R$",
:symbol_first => true,
:subunit => "Cent",
:subunit_to_unit => 100,
:thousands_separator => ".",
:decimal_mark => ","
}
end
在我的模型类“Produto”中:
class Produto < ApplicationRecord
attr_accessor :nome, :preco
monetize :preco_centavos
end
但是当我尝试在 Rails 控制台中使用它时,我得到了不同的行为:
irb(main):001:0> p = Produto.new
=> #<Produto id: nil, nome: nil, preco_centavos: 0, preco_currency: "BRL", created_at: nil, updated_at: nil>
irb(main):002:0> p.preco = 1000.to_money
=> #<Money fractional:100 currency:BRL>
irb(main):003:0> p.preco.format
=> "R$1,000.00"
当我期望“R$1.000,00”时,格式方法返回“R$1,000.00”。
有人已经通过了这个?
PS:对不起我的英语不好