Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveAdmin custom select filter dropdown names

For a user model I have a filter to check the booking status of a user which is represented by an integer value (0, 1, or 2).

The filter on the User ActiveAdmin index page is achieved with the following code:

  filter :booking_status, as: :select

However this results in the dropdown options being either 0, 1, or 2.

I would prefer if I could name them myself to something like "Incomplete", "Pending", and "Confirmed" when the admin user is selecting them from the dropdown.

enter image description here

Is there any way of doing this without changing how the booking_status is represented in the model?

like image 683
Conor Avatar asked Dec 05 '16 13:12

Conor


1 Answers

Assuming booking_status is an enum field in your model, you can use:

filter :booking_status, as: :select, collection: ModelName.booking_statuses

If booking_status is not an enum field, you can pass a regular hash to the collection option, something like:

filter :booking_status, as: :select, collection: {'Incomplete' => 0, 'Pending' => 1, 'Complete' => 2}

like image 192
eugen Avatar answered Nov 15 '22 16:11

eugen