问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/13403436/how-to-use-a-find-by-sql-query-for-an-activeadmin-index-page