rubyruby-on-rails-3ruby-on-rails-5chef-infrachef-recipe

How to fix this implicit error in my Ruby code


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.


Solution

  • 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"