我正在为大型生产应用程序开发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接口。他们只有相同的基础模型。
答案 0 :(得分:6)
Active Admin model代码:
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'
尝试以上更改。希望这能解决你的问题。感谢。