LoginSignup
1
2

More than 3 years have passed since last update.

ActiveAdmin における定義済みコールバック

Last updated at Posted at 2019-11-20

ドキュメントに見つからず、ソースを読んでいたら見つけたのでまとめ。

定義済みコールバック

コールバック new create update destroy
before_build, after_build o o
before_create, after_create o
before_update, after_update o
before_save, after_save o o
before_destroy, after_destroy o

使い方

controllerブロックを使わずに、すっきり書けます。

ActiveAdmin.register Post do
  after_build do |post|
    post.author = current_user
  end
end

controllerブロックで囲っても動作しました。

ActiveAdmin.register Post do
  controller do
    after_build do |post|
      post.author = current_user
    end
  end
end

ソース

ActiveSupport のコールバックを使わず、シンプルな実装が追加されています。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2