How to use a find_by_sql query for an ActiveAdmin index page?

霸气de小男生 提交于 2019-12-24 03:39:10

问题


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

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