私は同じ問題を抱えていたが、私は、インデックスフィルターとフォーム入力でカスタムを選択し必要なので、私は同様のソリューションを発見した:アプリ/入力(IN などをアプリ/入力/ filter_country_select_input.rで
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
:アプリ/入力/ country_select_input.rbで
:私は2 clasesを作成する)formtastic示唆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
そして、私のアプリ/管理/ 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
あなたが見ることができるように、ActiveAdminはフィルターを探し[:your_custom_name:]入力し、[:your_custom_name:]で入力異なるコンテキスト、索引フィルター、またはフォーム入力が含まれます。したがって、ActiveAdmin :: Inputs :: FilterSelectInputまたはFormtastic :: Inputs :: SelectInputのこの拡張を作成し、ロジックをカスタマイズすることができます。
それは私の作品、私はあなたがそれに便利