How to customize the display name of dynamic ActiveAdmin search filters

Working with ActiveAdmin

At Rootstrap, my first assignment was to develop a Ruby on Rails application which uses ActiveAdmin (with ActiveAdmin Addons) as a framework to implement the user interface.

I had never used ActiveAdmin before and I found myself reading a lot of documentation of the gem, in some cases, the documentation was not enough. For example, when I tried to display a custom name on an AJAX’s search select filter at first it was a little tricky. So today I will show you how to do it, in the end, it’s really simple!

Showing our custom display_name

In this tutorial, you will learn how to customize the display_name of a search_select the filter provided by ActiveAdmin Addons.

Before starting we have to include in our Gemfile the activeadmin gem and activeadmin-addons gem.

In this example we are going to use a search select to filter people and search a person, our person model has two fields named first_name and last_name, and we want to display the full name of the person when we are searching it. The full_name is the concatenation of first_name and last_name.

Steps to show our custom display_name

Create a Search Select

First of all, you should create a search select input in ActiveAdmin. This can be used in many places but in this example, we are going to use it in a filter. To do that, go to an ActiveAdmin view and put this code on it:

      filter :person_id,
             as: :search_select_filter,
             fields: %i[first_name last_name],
             display_name: :full_name

(If you are going to use this on a form you have to change search_select_filter to search_select).

The fields array indicates the fields that are used to filter, our input will be matched with the first_name of a person or their last_name.

The display_name is the field that our filter is showing to us meanwhile we search.

Setting up the returned JSON

The search select input is requesting a JSON meanwhile the user is searching for a person, for example in this case the filter will be doing requests to this endpoint /admin/people and retrieving a JSON showing all model attributes from a person. This is auto-generated by ActiveAdmin, but we can overwrite the response.

In this application we are using JBuilder to render JSON response so we have to create a file in:


In our example, the view created is in


In this file we can write the custom JSON that we want to retrieve for example:

json.array!(@people) do |person|
  json.extract! person, :id, :full_name

Attention: full_name is a method on person model, we have to write that method in the model and not in a decorator because if we are using this search_select in edit/new view an error will raise when validation fails, ActiveAdmin will call a method from person model named full_name and not from the decorator.

Writing the full_name method

Just write the method that we want in app/models/person.rb:

def full_name
    [first_name, last_name].compact.join(' ')

And now our search select input is ready to display the person full name!

What we learned about Search Select Inputs?

In this article, we learned how to display a custom field in our search select inputs. This will help us to give better search feedback to the user and it can be used in many different scenarios. It also helps us take control of the JSON returned by ActiveAdmin to the input (by default, all attributes are returned and maybe that’s not good for us).


Select2_Search ActiveAdmin

Want to work with Juan Francisco Ferrari?
We are hiring :)

Thanks to the creation of blockchain technology in 2008, a lot of developments have occurred since. For example, the creation […]
June 15
5 min read
One of the most important western philosophers of all time, Aristotle once said – “Man is by nature a social […]
December 7
5 min read
Month-over-month growth is a key metric for measuring the growth of your business.
June 18
5 min read
Quality assurance teams can use various tools to improve a company’s software. For example, a QA engineer may use a stress […]
October 2
5 min read
Startup leaders are always about making contingency plans for when things go wrong. Preparing for the worst is great. But […]
September 28
5 min read
Behind every mobile application, a UI framework determines how developers create the application and how well it performs. Today, UI […]
September 23
5 min read
Handling data is a big part of developing applications with Django. To do that, we use Django’s ORM, from retrieving […]
September 21
5 min read
DevOps has grown to be the top software development methodology worldwide. DevOps prioritizes the company and the customer by improving […]
September 21
5 min read