How to fix this implicit error in my Ruby code

45 views Asked by At

In this line I am getting error

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

getting this error

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

Getting same if I remove .to_i.

1

There are 1 answers

1
thatway_3 On BEST ANSWER

One layer of your data might have array but you are expecting as hash.

See examples:

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