ruby - Money Rails - Order Of Amount And Currency -
does money-rails
gem require specific order of price
, currency
when initializing object? example, take @ following:
object.new(currency: 'jpy', price: 25) => #<object id: nil, price_cents: 25, currency: "jpy">
if specify price
first, incorrect value (2500) price:
object.new(price: 25, currency: 'jpy') => #<object id: nil, price_cents: 2500, currency: "jpy">
object
contains following: monetize :price_cents
.
it looks order matters currencies (including jpy because doesn't have cents). may not best solution if stuck, here did.
i added following self.monetize
method in money-rails
override initialize methods classes use it:
define_method "initialize" |opts = {}| opts = opts.deep_symbolize_keys opts = {currency: opts[:currency]}.merge(opts) super(opts) end
this way send currency first.
Comments
Post a Comment