[英]How to get ID of newly created object in ActiveAdmin?
我想在超級調用后獲取新創建對象的 ID
ActiveAdmin.register Account do
.
.
.
controller do
def create
.
.
.
super
// Get ID of the newly created Account object. I'm not sure if calling Account.last is reliable?
是的 account.last 也可以。 但是您可以在模型中創建一個方法來獲取創建的帳戶 ID。
after_save {id = self.id}
要知道創建是否成功,我調用resource.valid? 為了獲取 ID,我調用了 resource.id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.