我正在为一个大型生产应用程序开发ActiveAdmin应用程序.我目前正在尝试为两个activeadmin“实体”使用相同的模型.
所以,说我有
class Person < ActiveRecord::Base scope :special,where(:is_special => true) scope :ordinary,where(:is_special => false) end
我能做点什么吗
ActiveAdmin.register Person,:name => "Special People" do # columns,filters for special people controller do def scoped_collection Person.special end end end ActiveAdmin.register Person,:name => "Ordinary People" do # columns,filters for ordinary people controller do def scoped_collection Person.ordinary end end end
(我在这里编写语法来解释我想要做什么.)
这两种类型的人将显示为ActiveAdmin.register块中定义的菜单项和不同的CRUD接口.他们只有相同的底层模型.
解决方法
主动管理模型代码:
ActiveAdmin.register Person,as: "Special People" do scope :Special,default: true do |person| person = Person.special end controller do def scoped_collection Person.special end end end ActiveAdmin.register Person,as: "Ordinary People" do scope :Ordinary,default: true do |person| person = Person.ordinary end controller do def scoped_collection Person.ordinary end end end
现在在路线:
match '/admin/special_people/scoped_collection/:id' => 'admin/special_people#scoped_collection' match '/admin/ordinary_people/scoped_collection/:id' => 'admin/ordinary_people#scoped_collection'
尝试以上更改.希望这能解决您的问题.谢谢.