Get ID of Rails Model before saving…?

后端 未结 10 1226
鱼传尺愫
鱼传尺愫 2020-12-16 13:03

How do you get the id of a rails model before it is saved?

For example, if I create a new model instance, how can I get its ID before it is saved?

I know t

10条回答
  •  执念已碎
    2020-12-16 13:35

    I don't believe there are any workarounds since the id is actually generated by the database itself. The id should not be available until after the object has been saved to the database.

提交回复
热议问题