8

我正在为大型生产应用程序开发 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 界面。他们只会有相同的基础模型。

4

1 回答 1

6

活动管理员模型代码:

   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'

尝试上述更改。希望这能解决您的问题。谢谢。

于 2013-11-07T19:31:49.580 回答