【发布时间】:2018-11-15 17:14:50
【问题描述】:
我正在使用 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
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
【问题讨论】:
标签: ruby-on-rails-4 converter currency google-finance