Use ActiveRecord scope in ActiveAdmin filter

守給你的承諾、 提交于 2020-01-14 14:46:08

问题


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

And the question is how can I use this scope in activeadmin fiter?


回答1:


Addd to model:

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

and then in resource:

  filter :by_survey_name, as: :string


来源:https://stackoverflow.com/questions/31694398/use-activerecord-scope-in-activeadmin-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!