次のシリアライザがあります
私の画像テーブルには、IDが1,2,3,4のデータがあります
空の結果をスローする代わりに、シリアライザーに id を 5 として渡すと、次のように例外がスローされます。
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
なぜこれが発生し、どうすれば解決できますか。
def image_ids
image_id = Images.where(post_id: id).first
unless image_id.nil?
image_id = image_id.id
[image_id]
end
end