How to get the 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 a stone money-rails

.

+3


source to share


2 answers


The answer can be found at @aurelius link. Without using, exchange_to

there is a direct way to get just the exchange rate. Since I am using a google currency

gem and configured it as default_bank

in an initializer, I can get a speed like this:



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

      

+1


source


Have you tried this :



bank.get_rate(:LKR, :USD).to_f

      

+1


source







All Articles