0
运行到一个奇怪的错误,而在我的种子Rails:first_or_initialize(id:1)NoMethodError:未定义的方法`空?' 0:Fixnum对象
console> Model.where(association_id: 1).first
[]
console> Model.where(association_id: 1).first_or_initialize(...)
> Model Load (0.8ms) SELECT "models".* FROM "models" WHERE
"models"."association_id" = $1 ORDER BY "models"."id"
ASC LIMIT 1 [["association_id", 0]]
NoMethodError: undefined method `empty?' for 0:Fixnum
如何first_or_initialize ID身份使用使用first_or_initialize?
你用id表示什么?你的'first_or_initialize'的内容是什么?我刚刚尝试过,它工作正常。 –
@ Ryan-NealMes该方法不适用于我的这一个特定的模型有或没有内容。它在其他模型上工作得很好,但是当我在这个模型上使用它时抛出错误。我不知道为什么。 –