moorara
moorara

Reputation: 4226

How to add a report/custom page to ActiveAdmin?

I am using ActiveAdmin for my Ruby on Rails application. My model consists of a couple entites such as "Plan", "Country", etc. I would like to have custom page for reporting purposes. This page should work on a collection of selected plans. So, I need scopes and filters. Currently one page associated with "Plan" model for CRUD operations. I don't want to add anything else to my data model or database since I have everything I need in my current model. How could I make such a page and access it through the menu?

Could I associate another page with my "Plan" model as follows?

ActiveAdmin.register Plan do
  menu label: 'Report', parent: 'Planning', priority: 2
  ...
end

Could I have a custom page working on set of plans selected using scopes and filters?

ActiveAdmin.register_page 'Report' do
   menu parent: 'Planning', priority: 2
   ...
end

Or, how could I add a new page/route to the currently associated page with "Plan" model for reporting? Can collection_action help me? If yes, how could I exactly bring a collection of Plans and show them?

Upvotes: 0

Views: 1323

Answers (1)

nistvan
nistvan

Reputation: 2960

You can register your ActiveRecord model several times in ActiveAdmin as a new resource:

ActiveAdmin.register Plan, as: 'PlanReport' do
  menu label: 'Report', parent: 'Planning', priority: 2
  ...
end

In this file you can use all of the ActiveAdmin features like scope and filters.

https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#rename-the-resource

Upvotes: 2

Related Questions