ruby-on-rails-4 - Rails 中的 Google Finance 货币转换器问题
问题描述
我正在研究 Google 货币转换器,但它不起作用。它只是重定向到:
http://finance.google.com:80/bctzjpnsun/converter?a=1&from=EUR&to=USD
或者它给出错误 404 Not Found
这是我的代码:
宝石文件:
gem 'money'
gem 'google_currency', '~> 3.4.1'
转换法
def self.exchange_to_USD annual_salary, currency
begin
mothly_salary = annual_salary / 12
if currency.present?
salary = Money.new(mothly_salary, currency).exchange_to(:USD).fractional
else
salary = mothly_salary
end
rescue Money::Bank::UnknownRate => e
salary = mothly_salary
rescue Exception => e
salary = mothly_salary
end
salary
end
应用程序.rb 文件
require 'money'
require 'money/bank/google_currency'
# set the seconds after than the current rates are automatically expired
# by default, they never expire
Money::Bank::GoogleCurrency.ttl_in_seconds = 86400
# set default bank to instance of GoogleCurrency
Money.default_bank = Money::Bank::GoogleCurrency.new
解决方案
改为使用eu_central_bank
。
我们最终更换google_currency
了eu_central_bank
它,它非常简单并且效果很好。它是其中的一部分,RubyMoney
因此应该得到很好的维护。基本替换如下所示:
eu_central_bank = EuCentralBank.new
eu_central_bank.update_rates # TODO: Make this use a cache in a shared directory and just update it every day.
Money.default_bank = eu_central_bank
绝对是一个值得考虑的好选择。
推荐阅读
- java - 程序启动时清除java swing表单的所有文本字段
- apache-kafka - 在 Kafka 中轮询消费者组滞后于 HTTP
- r - 创建一个指示最大值的列
- azure - ApplicationInsight:在 Azure 门户上查看跟踪和错误的位置
- python - 如何对迭代器进行压缩?
- powershell - 为什么`Get-Help tree`显示`Pester`主题
- uicollectionview - 拖动 UICollectionViewCell 时如何实现透明背景或圆角
- ios - UIButton 导致无法识别的选择器发送到实例
- node.js - this.props.SignupUser 不是我的 SignupComponent 文件中的函数 有什么问题?
- php - 如何按数字之和对一串数字进行排序