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.
Is there any way of doing this without changing how the booking_status is represented in the model?
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}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With