简体   繁体   English

在 ActiveAdmin 过滤器中使用 ActiveRecord 范围

[英]Use ActiveRecord scope in ActiveAdmin filter

In my rails project I have model :在我的 rails 项目中,我有模型:

class Panel < ActiveRecord::Base
  has_many :surveys

  scope :by_survey_name, ->(survey_name) {
    joins(:surveys).where('surveys.survey_name LIKE (?)', "%#{survey_name}%")
  }
end

And the question is how can I use this scope in activeadmin fiter?问题是我如何在 activeadmin fiter 中使用这个范围?

Add to model:添加到模型:

  def self.ransackable_scopes(_auth_object = nil)
    [:by_survey_name]
  end

and then in resource:然后在资源中:

  filter :by_survey_name, as: :string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM