8

I'm working on an ActiveAdmin app for a large production application. I'm currently trying to use the same model for two activeadmin "entities".

So, say I have

class Person < ActiveRecord::Base

  scope :special, where(:is_special => true)
  scope :ordinary, where(:is_special => false)

end

Can I do something like

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

(I'm making up the syntax a bit here to explain what I want to do.)

The two types of people would appear as menu items and different CRUD interfaces as defined in the ActiveAdmin.register block. They would just have the same underlying model.

mattfitzgerald
  • 353
  • 2
  • 14
  • did you try your solution ? – Fivell Jun 17 '13 at 11:14
  • What happen if you execute your code? – monteirobrena Jun 20 '13 at 19:56
  • I use :as option as follows: ActiveAdmin.register Person, :as => "Ordinary People" This works for me locally but sometimes remotely both declarations clash and the routes redirect to the wrong controller. I haven't been able to track down where in the initialization process this is happening though. – polmiro Jul 12 '13 at 23:43
  • Have you seen this answer? I hope this helps you. http://stackoverflow.com/questions/16546502/two-pages-for-the-same-resource-activeadmin – Misha Jul 23 '13 at 06:32

1 Answers1

6

Active Admin model Code:

   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

Now in routes:

match '/admin/special_people/scoped_collection/:id' => 'admin/special_people#scoped_collection'

match '/admin/ordinary_people/scoped_collection/:id' => 'admin/ordinary_people#scoped_collection'

Try with above changes. Hope this would solve your issues. Thanks.

Swati
  • 842
  • 10
  • 26