ruby-on-rails-3 – 在两个活动的管理类中使用相同的模型

我正在为一个大型生产应用程序开发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'

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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...