如何修复我的 Ruby 代码中的隐式错误

How to fix this implicit error in my Ruby code

在这一行我收到错误

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

您的数据的一层可能有数组,但您期望的是散列。

查看示例:

hash = { foo: [{ bar: "baz" }]}
=>  hash[:foo][:bar]
TypeError: no implicit conversion of Symbol into Integer
hash = { foo: [{ bar: "baz" }]}
=>  hash[:foo].first[:bar]
"baz"