LoginSignup
9
7

More than 5 years have passed since last update.

ActiveAdminにカスタムページを追加する

Posted at

モデルのCRUDと関係ないページ、およびそのページヘのリンクをナビゲーション・メニューに追加したい場合は以下のようにすると良いと思う。

Controllerの作成

  • ここではカスタムページのControllerをAdminCustomControllerとする
  • rails g controller AdminCustomControllerとかでadmin_custom_controller.rbを作る

Viewの作成

  • app/view/admin_custom/_index.html.erbファイルを作る
    • _で始めることに注意
  • このファイルに管理画面上で表示するページのHTMLを書く

管理画面とのひもづけ

  • app/admin/custom.rbファイルを作り以下のように編集する
custom.rb
ActiveAdmin.register_page "Custom" do
  content do
    render partial: 'admin/custom/index'
  end
end
  • "Custom"の部分はページ及びナビゲーション・メニューで表示されるタイトルになる
  • render partialに続く部分は、先ほど作ったページのテンプレートを指定
    • partialになっているのは、ナビゲーション・メニューなどヘッダやフッタはActiveAdminのレイアウトを使うからである
9
7
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
9
7