简体   繁体   中英

Rails currency exchange gem that works?

Just wondering if anyone has used a currency exchange ruby gem that gets exchange rates from an external api and actually works. I have tried the following gems but have not been able to get any of them to function as described:

goog_currency, yahoo_currency, google_currency, yahoo_finance_currency

One of these uses deprecated code and hence does not work correctly.

I am just trying to display a currency exchange rate in a rails view which has been grabbed from an external api.

I have also considered trying to parse the json from yahoo/google finance urls but this seems much harder to do than it should.

I picked google_currency from your list as most popular and it has been recently maintained. It worked fine for me, I ran the code from the synopsis without a problem.

If you saw the message:

You are using an old or stdlib version of json gem
Please upgrade to the recent version by adding this to your Gemfile:

  gem 'json', '~> 1.7.7'

Then you may need to update your copy of multi_json to avoid the json deprecation warnings:

gem install json
gem install multi_json

Which should (at the time of writing) install json 1.8.0 and multi_json 1.7.8. Or of course, if this is for a project, you should be able to pick these versions in your Gemfile , provided there is no conflict with other libraries in your project. The message may of caused you concern, but it is not a problem with google_currency .

I didn't notice any conflict or problems with the google_currency gem, using either the deprecated JSON modules or the most recent ones. To do something similar to what you want:

require 'money'
require 'money/bank/google_currency'

bank = Money::Bank::GoogleCurrency.new
bank.get_rate(:GBP, :USD).to_f
 => 1.5513

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM