LoginSignup
4
3

More than 5 years have passed since last update.

ActiveAdminのタイトル右にあるボタン(アクションアイテム)をカスタマイズする

Posted at

デフォルトだとそれぞれの画面で、自動的に配置されてしまうので、場合によっては都合が悪いです。すべてのアクションアイテムを画面ごとに明示的に配置したい場合は、以下のようにすると良いでしょう。

ActiveAdmin.register User do
  # これでアクションアイテムの自動配置が行われなくなる
  config.clear_action_items!

  #
  # indexアクション(一覧画面)でのみ、表示するアクションアイテムボタン
  #
  action_item :my_button1, only: :index do
    link_to "MyButton1", action: :my_button_action1
  end
  action_item :my_button1, only: :index do
    link_to "MyButton2", action: :my_button_action2
  end
end
  • action_itemで配置
  • only: の後にアクションアイテムボタンを表示するアクションを指定する
  • ブロック内でlink_toを使ってボタン生成
  • ブロック内でnilを返すとボタン表示されない
    • つまり条件分岐で表示・非表示を制御できる
  • 複数配置したい時は複数回action_itemを呼ぶ出す
  • 呼び出した順に左から右へ並ぶ
4
3
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
4
3