4

Using the money-rails gem https://github.com/RubyMoney/money-rails

I've previously been using the with_model_currency method:

delegate :currency, :to => :edition, :prefix => true

monetize :base_fee_pennies, :allow_nil => true, :with_model_currency => :edition_currency
monetize :qm_fee_pennies, :allow_nil => true, :with_model_currency => :edition_currency
monetize :total_fee_pennies, :allow_nil => true, :with_model_currency => :edition_currency

But I'm trying to find a more succinct way to do this so instead of using with_model_currency 3 times, so I started overriding the currency method directly:

def currency # previously currency_for_price?
  unless new_record?
    Money::Currency.find(edition_currency)
  end
end

But found that I have problems on new records... the edition_id is set using the build method, but this doesn't work for some reason, I get errors that the edition is not set, so I used the new_record? method which seems to fix it.

My question is whether or not this is the way I should go about doing this or if there's a more direct approach (aside from making a column).

Thanks,

holden
  • 13,471
  • 22
  • 98
  • 160

0 Answers0