如何对ActiveAdmin索引页使用find_by_sql查询? [英] How to use a find_by_sql query for an ActiveAdmin index page?
问题描述
我在一个项目上使用活动管理员。我有一个创建新资源的请求,并获得了要使用的复杂SQL查询-它连接到另一个数据库。一切都很好-但是,我是ActiveAdmin的新手,并且很好奇如何获取索引页以使用我的自定义查询和默认资源。
I'm using active admin on a project. I have a request to create a new resource and was given a complex SQL query to use - which connects to a different DB. All is good - however, I'm somewhat new to ActiveAdmin and curious how to get the index page to use my custom query vs. the default resource.
我只需要轻推/样本以查看如何覆盖此默认活动。
I just need a nudge/sample to see how to override this default activity.
推荐答案
向ActiveAdmin注册模型时,您可以声明范围和过滤器。
You can declare scopes and filters when registering your model with ActiveAdmin.
app / model / your_model.rb
class YourModel < ActiveRecord::Base
scope :my_scope, where('some custom SQL')
scope :my_other_scope, where('some other custom SQL')
end
app / admin / your_models.rb
ActiveAdmin.register YourModel do
scope :my_scope, default: true
scope :my_other_scope
end
这篇关于如何对ActiveAdmin索引页使用find_by_sql查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!