2013-12-16 37 views
1

我正在使用Money gem來處理交易金額。我想爲不同的交易使用不同的貨幣(但沒有轉換)。默認貨幣設置在money.rb:即使Rails money gem - 無法覆蓋默認貨幣

config.default_currency = :usd 

我可以在創建交易時設置不同的貨幣,視圖始終顯示在美元金額。例如,這個以RUB爲貨幣的12.00交易:

<Transaction id: 100, amount_cents: 1200, currency: "RUB", created_at: "2013-12-11 09:32:52", updated_at: "2013-12-11 09:32:52"> 

在我的觀點中顯示爲USD交易。

<% transactions.each do |transaction| %> 
    <%= transaction.amount_cents.to_money.format %> 
... 

=> $12.00 

這裏是(我的思念以防萬一)的代碼從我Transaction.rb

composed_of :amount_cents, 
       class_name: 'Money', 
       mapping: %w(amount_cents cents), 
       converter: Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : Money.empty }    

    monetize :amount_cents, as: "amount" 

如何覆蓋默認的任何想法?我會感謝任何建議。

回答

2

使用金額而不是amount_cents解決了該問題。