小编nof*_*off的帖子

分配变量时“nil 不能被强制转换为整数”(仅限)

红宝石'2.7.3'导轨(6.1.4.1)

看起来很奇怪:

当我使用 activerecord 查询数据库中的某些(某些特定)行并尝试将其分配给变量时,它会引发“nil 无法强制转换为整数”

但是当我不尝试将其分配给变量时,它会起作用:

Recipient.find(45638)
 => #<Recipient id: 45638, company_id: 7, callout_id: 18, phone: "***", created_at: "2022-02-14 02:14:04.816032000 +0000", updated_at: "2022-02-15 06:50:37.828979000 +0000", payload: {"first_name"=>"", "last_name"=>"", "lead_id"=>"388014"}, started_at: nil, finished_at: 1644907333994, call_duration: 95, call_result: nil, report_data: {"Recording"=>"...", "UF_CRM_1601886091616"=>"76"}, job_status: "longCallWithResult", job_id: "2105242339", aasm_state: "finished", attempts: 1, tag: "...", tag_payload: {}, code: "37cca71006817c4f9e2e172d4e0afe80", schedule_at: "2022-02-11 09:07:47.000000000 +0000", synced_to_external_crm: false> 

2.7.3 :035 > recipient = Recipient.find(45638)
Traceback (most recent call last):
TypeError (nil can't be coerced into Integer)
Run Code Online (Sandbox Code Playgroud)

它仅发生在数据库中的特定行上。不仅对于模型对象,对于 …

ruby ruby-on-rails

9
推荐指数
1
解决办法
1178
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1