Active Admin - Custom Pages, Views and Actions

Active Admin is a Ruby on Rails plugin to generate Admin console for the application. It has a lots of functionalities implemented out of the box where we just need to integrate it and use it. Most of the time you don’t need to customize the plugin.

But the main Advantage of Active Admin is that you can customize almost all the built-in functionalities. The main functionalities are: Navigation, User Authentication, Scopes, Action Items, Index styles, Filters, Sidebar sections, API and Downloads.

By default Active Admin will generate the pages to CRUD a model when you generate the resource file for the model using rails generator:

    $> rails generate active_admin:resource [MyModelName]

But what if in your application you need an Admin page where you want to show some calculated data of a model or multiple models which is obviously not a resource file. You can create custom pages:

Now you can put your view/html content in the partial:

This is enough to create a simple custom page which will show the data in a customized view. But in some situation you need a button to perform some operations like download the data. In those situations you need custom action and action item. Modified custom page:

You can also add custom filters to filter the data. You just need to add the following line to the custom page:

      sidebar :filter, partial: 'filter'

and create a view for the filter partial

You need to use the filter params in your custom page to filter the data:

      Transaction.where(:type => /.*#{params[:type]}.*/)

As I mentioned before, this is the greatest advantage of using Active Admin. You can customize almost all the functionalities :)

blog comments powered by Disqus
Operator method call in Ruby →
← Integrating FriendlyID, Inh...