如何为Activeadmin嵌套资源过滤器提供集合?

时间:2016-11-22 07:20:25

标签: ruby-on-rails activeadmin

如何提供与群组相关联的收藏用户?

has_many :users, through: :group_settings
has_many :groups, through: :group_settings

ActiveAdmin.register Group do
  ActiveAdmin.register GroupSetting do
    belongs_to :group
    filter :user_email, as: :select, collection: Users.????, label: 'Email'
  end
end

谢谢!

1 个答案:

答案 0 :(得分:0)

解决您的用户可能属于多个群组的情况:

在你的模特中:

has_and_belongs_to_many :groups

scope :with_group_id, ->(group_id) { joins(:groups).where(groups: {id: [*group_id] } ) }

和用法:

User.with_group_id([2,5])

其中2和5 - 组ID