9
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ActiveAdmin 独自のindexを作る

Posted at

ActiveAdminで管理画面を作るとき、indexページをカスタマイズしたいと思ってググると、だいたいここにたどり着く。

activeadmin/3-index-pages.md at master · activeadmin/activeadmin

Tableの他、Grid、Blocks、Blogなんかが選べるよ!

...そうじゃなくて、もっと完全にカスタマイズしたい場合は?

Custom Indexを作ってね

で、このCustom Indexがよくわからんので、ドツボにはまる。

indexとして単なるViewを表示する

 実は、activeAdminのindexページとして単なるview templateを表示することができる。

たとえばapp/views/active_admin/_tree.haml を作って

Hello View World!

indexページに指定してやれば、そのViewがそのまま表示される

ActiveAdmin.register Category do
  index do
    render partial: 'active_admin/tree'
  end

Tag_Categories___Dengenmap 3.png

こんにちはいつものRailsの世界。

collectionsを表示する

で、このViewには、いつものrails同様、インスタンス変数で表示すべきcollectionsが渡されてくるので、これを使えば、任意のデザインでindexを出力することができる。

.row
  - @categories.each do |tc|
:

(app/views/active_admin/_tree.haml)

Tag_Categories___Dengenmap 2.png

当然の事ながら、Collectionとして渡されてくるのはFilterで絞り込んだあとのデータなので、Filterで絞り込んだらViewにもその内容が自動的に反映される。

Tag_Categories___Dengenmap.png

CustomIndexなんていらんかったんや!

9
11
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
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?