I am trying to determine why I am not able to obtain the ID of a model after it is saved to the database:
我试图确定为什么在将模型保存到数据库后无法获取模型的ID:
request.attributes = attributes
request.touch
request.save!
puts request.inspect
The console prints:
控制台打印:
#<Request id: nil, ...>
using:
使用:
activerecord (4.2.9)
activerecord-sqlserver-adapter (4.2.18)
activesupport (4.2.9)
rails (4.2.9)
1 个解决方案
#1
0
you might try to reload model and inspect it again:
您可能会尝试重新加载模型并再次检查它:
request.reload
puts request.last.inspect
though according to your code snippet the model must be persisted - save!
would throw error otherwise.
虽然根据你的代码片段,模型必须保持 - 保存!否则会抛出错误。
P.S. I'd rather leave a comment on your question but don't have enough reputation.
附:我宁愿对你的问题发表评论,但没有足够的声誉。
#1
0
you might try to reload model and inspect it again:
您可能会尝试重新加载模型并再次检查它:
request.reload
puts request.last.inspect
though according to your code snippet the model must be persisted - save!
would throw error otherwise.
虽然根据你的代码片段,模型必须保持 - 保存!否则会抛出错误。
P.S. I'd rather leave a comment on your question but don't have enough reputation.
附:我宁愿对你的问题发表评论,但没有足够的声誉。