miałem ten sam problem, ale muszę niestandardowy wybierz w filtrach indeksowych i wejść formy, więc znalazłem podobnego rozwiązania: w APP/wejść (jak proponuję formtastic) tworzę dwa clases:
w aPP/wejść/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
w aPP/wejść/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
I w moim 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
Jak widać, ActiveAdmin szukać Filtr [: your_custom_name:] [: wejściowy i your_custom_name:] Wejście w inny kontekst, filtry indeksu lub dane wejściowe formularza. Tak więc możesz utworzyć rozszerzenie klauzuli ActiveAdmin :: Inputs :: FilterSelectInput lub Formtastic :: Inputs :: SelectInput i dostosować swoją logikę.
To działa dla mnie, mam nadzieję, że może okazać się przydatny