administrate gemを使用しています。ユーザーのコレクションがありhas_many
、そのユーザー ダッシュボードで関係を表示しています。
現在、私のuser_dashboardは次のようになっています
class UserDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
...
sub_items: Field::HasMany.with_options(limit: 10)
}
現在、これはデフォルトで機能しますが、問題は、通常は問題ないユーザーのすべてを表示していることですが、特定のタイプがある場合にのみ関係を表示しようとしています。たとえば、デフォルトではすべてを表示するのではなく、sub_items
has_many
user.sub_items
user.sub_items.where(category: [arr_of_options], sub_category: [arr_of_options])
今、私は試しました
- ここに示されているオプションを渡すhttps://github.com/thoughtbot/administrate/blob/master/docs/customizing_dashboards.mdしかし、コレクション/条件付きオプションはありません
Field::HasMany
- ビューに特定の has_many コレクションのみを表示します。この場合は になります
admin/users/show.html.erb
。これはおそらく可能ですが、ここでそうするのは本当に面倒です - admin/users_controllerでフィルタリングを試みましたが、コントローラーは
requested_resource
そのリソースのサブオブジェクトではなく、サブオブジェクトのみを提供すると思います
管理ダッシュボードに特定のhas_many オブジェクトのみを表示する方法を知っている人はいますか?