在ActiveAdmin过滤器中使用ActiveRecord范围

时间:2015-07-29 07:51:29

标签: ruby-on-rails ruby activerecord activeadmin

在我的rails项目中,我有模型:

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中使用此范围?

1 个答案:

答案 0 :(得分:6)

添加到模型:

(defn test-fn []
  (client/head "https://google.com/404")
)

(with-handler! #'test-fn
           java.lang.Exception
          (fn [e] "error!"))

然后在资源中:

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