ActiveAdmin - Using scopes with filters

你离开我真会死。 提交于 2019-12-03 07:11:36

Rather than scope create another filter which will select the records on criterion based on if examples are deleted or all. And apply as many filter as you want.

Or in filter while calculating the selector on which you will run the filter run the scope accordingly and then put the filter conditions on that selector.

By default, ActiveAdmin wants scopes to just provide a symbolized method name. When you define scopes this way, they can be chained to the scoping already provided by filters and they work together seamlessly.

So your mistake is explicitly calling Model#class_method instead of providing :symbolized_class_method_name (with an implied owner of the current model).

Filters and scopes will work together if you replace this code:

scope :all do |example|
  Example.with_deleted
end

scope :deleted do |example|
  Example.only_deleted
end

With this:

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