如何在我的Ruby代码中解决此隐式错误

问题描述 投票:0回答:1

在此行,我得到了错误

node.default['aem_dispatcher_cookbook']['ip_address'] = nodes.first('ipaddress').to_i  

收到此错误

Recipe Compile Error in /root/.chef/local-mode-cache/cache/cookbooks/aem_dispatcher_cookbook/recipes/default.rb
================================================================================
TypeError --------- no implicit conversion of String into Integer

如果删除.to_i,也会得到相同的结果。

ruby ruby-on-rails-3 ruby-on-rails-5 chef chef-recipe
1个回答
0
投票

数据的一层可能具有数组,但是您希望将其作为哈希值。

查看示例:

hash = { foo: [{ bar: "baz" }]}
=>  hash[:foo][:bar]
TypeError: no implicit conversion of Symbol into Integer
hash = { foo: [{ bar: "baz" }]}
=>  hash[:foo].first[:bar]
"baz"
© www.soinside.com 2019 - 2024. All rights reserved.