Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

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!

MoRo-oRoM
気ままにコーディング Ruby/Go/Java/JavaScript
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away