Ruby - 字符串的未定义方法"map"



我无法将字符串数组转换为整数。我得到以下错误undefined method map for "["118", "119"]":String.

你知道怎么解决这个问题吗?

def job_template_by_id
job_template_id = var_search(@handle.object, 'job_template_id') ||
var_search(@handle.object, 'dialog_job_template_id')

job_template_id = job_template_id.map(&:to_i)
@handle.vmdb(SCRIPT_CLASS).where(:id => job_template_id) if job_template_id
end

错误:

[----] E, [2022-07-07T16:08:09.928258 #534:2afb827cdb68] ERROR -- automation: Q-task_id([r837_miq_provision_2172]) <AEMethod launch_ansible_job> The following error occurred during method evaluation:
[----] E, [2022-07-07T16:08:09.930286 #534:2afb827cdb68] ERROR -- automation: Q-task_id([r837_miq_provision_2172]) <AEMethod launch_ansible_job>   NoMethodError: undefined method `map' for "["118", "119"]":String
[----] E, [2022-07-07T16:08:09.931630 #534:2afb827cdb68] ERROR -- automation: Q-task_id([r837_miq_provision_2172]) <AEMethod launch_ansible_job>   /ManageIQ_Custom/AutomationManagement/AnsibleTower/Operations/StateMachines/Job/launch_ansible_job:113:in `job_template_by_id'

,错误说这不是你期望一个数组,它可能是一个字符串,JSON。所以你需要首先解析它

job_template_id = JSON.parse(job_template_id).map(&:to_i)

相关内容

  • 没有找到相关文章

最新更新