Google rails 中的金融货币转换器问题
Google Finance currency converter issue in rails
我正在研究 Google 货币转换器,但它不工作。它只是重定向到:
http://finance.google.com:80/bctzjpnsun/converter?a=1&from=EUR&to=USD
或者它给出错误 404 Not Found
这是我的代码:
gem 文件:
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
application.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
Google 贬低了这种检索利率的方式。以前 "bctzjpnsun" link 是获取它们的另一种方式,但最近被关闭了(可能是 2018 年 6 月 1 日)。
您可以在这里找到一些替代服务:
改用eu_central_bank
。
我们最终用 eu_central_bank
替换了 google_currency
,这非常简单而且效果很好。它是 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
绝对是一个不错的选择。
我正在研究 Google 货币转换器,但它不工作。它只是重定向到:
http://finance.google.com:80/bctzjpnsun/converter?a=1&from=EUR&to=USD
或者它给出错误 404 Not Found
这是我的代码:
gem 文件:
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
application.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
Google 贬低了这种检索利率的方式。以前 "bctzjpnsun" link 是获取它们的另一种方式,但最近被关闭了(可能是 2018 年 6 月 1 日)。
您可以在这里找到一些替代服务:
改用eu_central_bank
。
我们最终用 eu_central_bank
替换了 google_currency
,这非常简单而且效果很好。它是 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
绝对是一个不错的选择。