-1

我想在我的机器中使用金钱宝石,但我得到以下错误。钱宝石 - 未定义的方法`每个'零:NilClass

我指的这个链接 - https://github.com/RubyMoney/money/blob/master/README.md

Money.new(1000, "USD").exchange_to("EUR") 
NoMethodError: undefined method `each' for nil:NilClass 
    from /home/dev/new_hotspotting-backend/shared/bundle/ruby/2.3.0/gems/money-currencylayer-bank-0.5.3/lib/money/bank/currencylayer_bank.rb:93:in `update_rates' 
    from /home/dev/new_hotspotting-backend/shared/bundle/ruby/2.3.0/gems/money-currencylayer-bank-0.5.3/lib/money/bank/currencylayer_bank.rb:142:in `expire_rates!' 
    from /home/dev/new_hotspotting-backend/shared/bundle/ruby/2.3.0/gems/money-currencylayer-bank-0.5.3/lib/money/bank/currencylayer_bank.rb:108:in `get_rate' 
    from /home/dev/new_hotspotting-backend/shared/bundle/ruby/2.3.0/gems/money-6.7.0/lib/money/bank/variable_exchange.rb:109:in `exchange_with' 
    from /home/dev/new_hotspotting-backend/shared/bundle/ruby/2.3.0/gems/money-6.7.0/lib/money/money.rb:434:in `exchange_to' 
    from (irb):17 

我不明白为什么我得到这个错误。 我使用以下版本的钱宝石

money (6.9.0, 6.7.0) 
money-currencylayer-bank (0.5.4) 

enter image description here

+0

我也试图改变版本的钱宝石,但仍然得到同样的问题。 –

+0

金钱宝石的其他功能正在工作,但只有exchange_to不起作用 –

+0

要做'交换'你必须[提供一个速率来源](https://github.com/RubyMoney/money/blob/master/README.md#currency -交换)。 – mudasobwa

回答

2

尝试:

对象需要一个手动指定汇率

Money.add_rate("USD", "EUR", 0.5) 
Money.us_dollar(100).exchange_to("EUR") 

更多official GEM rapo

outp ut:

2.3.0 :009 > 
2.3.0 :010 > require 'money' 
=> true 
2.3.0 :011 > Money.add_rate("USD", "EUR", 0.5) 
=> 0.5 
2.3.0 :012 > Money.us_dollar(100).exchange_to("EUR").currency 
=> #<Money::Currency id: eur, priority: 2, symbol_first: true, thousands_separator: ., html_entity: &#x20AC;, decimal_mark: ,, name: Euro, symbol: €, subunit_to_unit: 100, exponent: 2, iso_code: EUR, iso_numeric: 978, subunit: Cent, smallest_denomination: 1> 
2.3.0 :013 > 
2.3.0 :014 > 
+0

仍然有相同的错误。 –

+0

你能发送你的代码吗,你在代码上犯了一些小错误。请用代码 – vipin

+0

更新你的问题我上传的图片。请检查一下。 –

相关问题