Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Admin: How to customize labels for select filter?

This seems like it should be fairly simple, buy I haven't been able to find any documentation on the subject.

I have the following filter:

filter :archived, as: :select

...which gives me a working filter in the form of a select box with options "Any", "Yes", and "No".

My question is: How do I customize these labels such that the functionality remains the same, but the labels are instead "All", "Live", and "Archived"?

like image 914
Austin York Avatar asked Apr 06 '13 15:04

Austin York


1 Answers

The quick and easy:

filter :archived, as: :select, collection: [['Live', 'true'], ['Archived', 'false']]

However, that won't give you a way to customize the "All" option without changing I18n.

UPDATED: Here's another option:

# Somewhere, in an initializer or just straight in your activeadmin file:
class ActiveAdmin::Inputs::FilterIsArchivedInput < ActiveAdmin::Inputs::FilterSelectInput
  def input_options
    super.merge include_blank: 'All'
  end

  def collection
    [ ['Live', 'true'], ['Archived', 'false'] ]
  end
end

# In activeadmin
filter :archived, as: :is_archived
like image 154
Amiel Martin Avatar answered Sep 24 '22 02:09

Amiel Martin