Search code examples
ruby-on-railscurrencymoney-rails

How to get the exchange currency exchange rate in rails?


I tried to get the exchange rate like this in my Rails app :

1.to_money.exchange_to('USD')

(Note : I have set the default currency to my local currency which is lkr). This returns 0. Im using the money-rails gem.


Solution

  • The answer can be found from the link @aurelius have posted. Without using exchange_to, there's a direct way to get just the exchange rate. Since I use google currency gem and have configured it as the default_bank in the initializer, I can get the rate like this :

    MoneyRails.default_bank.get_rate(:LKR, :USD)