簡體   English   中英

如何在 ActiveAdmin 中獲取新創建對象的 ID?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM