I'm working on a web application based on Active Admin and am trying to understand how to create a select filter that is dynamically populated with all the unique values from a particular field.
From my understanding Active Admin uses Formtastic for these.
The scenario is countries and the code below from the resource works correctly and inserts Austria & France into the select.
But how do I this dynamically, as in, how do I go and query all the possible unique country options, and insert them into this collection?
filter :Country, :as => :select, :collection => ["Austria", "France"]
Should I do this work in the model first and then link to it in the resource?
Appreciate your help.
Thanks so much.
EDIT: Based on comments, I've now tried this, but it is erroring:
filter :Country2, :as => :select, :collection => proc { Country.all.collect {|country| country.name}.uniq }
Erorr message: uninitialized constant Country
FYI model name is Dailydeal
EDIT 2:
Here is the new working code
filter :Country, :as => :select, :collection => proc { Dailydeal.all.collect {|dd| dd.Country}.uniq }