ActiveAdmin 選択フィルター コレクション
概要
Rails 4を使用してActiveAdmin(1.0.0pre4)でカテゴリ選択フィルタを作成しようとしています。各企業には異なるカテゴリがあります。 current_user の会社に基づいたフィルター コレクションを作成するにはどうすればよいですか?
filter :by_category,
as: :select,
collection: proc { Category.by_company(current_company) }
これにより、#
周囲のprocを削除すると、サーバーの起動時に次のエラーが発生します。
undefined local variable or method 'current_company' for #<ActiveAdmin::ResourceDSL:0x007fb8a8c332b0> (NameError)
ActiveAdmin 1.0.0pre4 でこれを行うことは可能ですか?
解決策
current_user から current_company を取得できますか?つまり、current_user.company
もしそうなら、
filter :by_category,
as: :select,
collection: proc { Category.by_company(current_user.company) },
label: 'Category'