LoginSignup
3
2

More than 5 years have passed since last update.

ActiveAdminで2回以上のrelationを挟むカラムのfilterの仕方

Last updated at Posted at 2018-07-25

モデルの構成は以下のようにする

website.rb
class Website < ApplicationRecord
 belongs_to :category
end
category.rb
class Category < ApplicationRecord
  has_many :websites
  belongs_to :article
end
article.rb
class Article < AppricationRecord
  has_many :articles
end

会社でactive_adminで階層構造のfilterをかける時一瞬手が止まったので、メモ
website一覧で、articleごとのwebsite一覧を検索する場合

admin/website.rb
...

filter :category_article_id, label: I18n.t('activerecord.models.article'), as: :select, collection: proc {Article.all.map{|a| [a.title, a.id]}}

...

上記のようにかけば良い

active_admin管理画面としてはピカイチ

Thank you for reading!

3
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
3
2