Rails货币兑换宝石的作品? [英] Rails currency exchange gem that works?

查看:110
本文介绍了Rails货币兑换宝石的作品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否有人使用外汇交易红宝石,从外部API获得汇率,实际上是有效的。我已经尝试了以下宝石,但一直未能让它们中的任何一个按照所述的方式工作:



goog_currency,yahoo_currency,google_currency,yahoo_finance_currency



其中一个使用不推荐使用的代码,因此无法正常工作。



我试图在外部API抓取的Rails视图中显示货币汇率。



我也考虑过试图从雅虎/谷歌财经网站解析json,但这似乎比它应该做得难。

解决方案

我从您的清单中选择了 google_currency 最近保持不变。它对我来说很好,我从简介中运行代码时没有问题。



如果您看到以下消息:

 您使用的是旧版本或stdlib版本的json gem 
请将您的Gemfile添加到最新版本中:

gem' json','〜> 1.7.7'

然后您可能需要更新 multi_json 以避免json弃用警告:

  gem install json 
gem install multi_json

应该在撰写本文时安装json 1.8.0和multi_json 1.7.8。或者当然,如果这是一个项目,你应该能够在 Gemfile 中选择这些版本,前提是与项目中的其他库没有冲突。该消息可能会引起您的关注,但它不是 google_currency 的问题。



我没有注意到与 google_currency gem之间的任何冲突或问题,使用不推荐的JSON模块或最新的模块。要做类似于你想要的东西:

 需要'钱'
需要'钱/银行/谷歌货币'

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


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

这篇关于Rails货币兑换宝石的作品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆