在ActiveAdmin过滤器中使用ActiveRecord范围 [英] Use ActiveRecord scope in ActiveAdmin filter
本文介绍了在ActiveAdmin过滤器中使用ActiveRecord范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的rails项目中,我有一个模型:
In my rails project I have model :
class Panel < ActiveRecord::Base
has_many :surveys
scope :by_survey_name, ->(survey_name) {
joins(:surveys).where('surveys.survey_name LIKE (?)', "%#{survey_name}%")
}
end
问题是如何在activeadmin fiter中使用此范围?
And the question is how can I use this scope in activeadmin fiter?
推荐答案
添加到模型:
def self.ransackable_scopes(_auth_object = nil)
[:by_survey_name]
end
然后在资源中:
filter :by_survey_name, as: :string
这篇关于在ActiveAdmin过滤器中使用ActiveRecord范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文