【问题标题】:How to fix this implicit error in my Ruby code如何在我的 Ruby 代码中修复这个隐式错误
【发布时间】:2020-05-21 14:33:52
【问题描述】:

在这一行我收到错误

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-infra chef-recipe


    【解决方案1】:

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

    查看示例:

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

    【讨论】:

    • 实际上我正在尝试在厨师代码publish_vm = 'apvrp27560' nodes = search(:node, 'hostname:publish_vm') node.default['aem_dispatcher_cookbook']['ip_address'] = nodes.first('ipaddress') 中获取其他系统的 IP 地址,这是我尝试过的代码,但没有得到你能检查一下吗
    猜你喜欢
    • 2022-01-11
    • 2023-01-20
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多