ich hatte das gleiche Problem, aber ich brauche individuelle Auswahl in Index-Filter und Formulareingaben, so habe ich eine ähnliche Lösung gefunden: In app/Eingänge (wie vorschlagen formtastic) ich schaffe zwei clases:
In app/Ein-/country_select_input.rb:
class CountrySelectInput < Formtastic::Inputs::SelectInput
def collection
I18nCountrySelect::Countries::COUNTRY_CODES.map { |country_code|
translation = I18n.t(country_code, scope: :countries, default: 'missing')
translation == 'missing' ? nil : [translation, country_code]
}.compact.sort
end
end
In app/Ein-/filter_country_select_input.r b:
class FilterCountrySelectInput < ActiveAdmin::Inputs::FilterSelectInput
def collection
I18nCountrySelect::Countries::COUNTRY_CODES.map { |country_code|
translation = I18n.t(country_code, scope: :countries, default: 'missing')
translation == 'missing' ? nil : [translation, country_code]
}.compact.sort
end
end
Und in meiner app/admin/city.rb:
ActiveAdmin.register City do
index do
column :name
column :country_code, sortable: :country_code do |city|
I18n.t(city.country_code, scope: :countries)
end
column :created_at
column :updated_at
default_actions
end
filter :name
filter :country_code, as: :country_select
filter :created_at
form do |f|
f.inputs do
f.input :name
f.input :country_code, as: :country_select
end
f.actions
end
end
Wie Sie sehen können, ActiveAdmin sucht Filter [: your_custom_name:] Eingabe und [: your_custom_name:] Eingang in unterschiedlicher Kontext, Indexfilter oder Formulareingaben. So können Sie diese Erweiterung von ActiveAdmin :: Inputs :: FilterSelectInput oder Formtastic :: Inputs :: SelectInput erstellen und Ihre Logik anpassen.
Es funktioniert für mich, ich hoffe, Sie finden es nützlich