I am working with the administrate gem. I have a collection of users and am showing a has_many
relationship in that user dashboard.
Right now, my user_dashboard looks like
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)
}
Right now, this works by default, but the problem is it is showing all of the sub_items
for a user which would normally be fine, but I am trying to only show the has_many
relationship if it has a certain type to it. For example, by default I do not want to show all of the user.sub_items
, I only want to show the user.sub_items.where(category: [arr_of_options], sub_category: [arr_of_options])
Right now, I have tried
- to pass in options shown here https://github.com/thoughtbot/administrate/blob/master/docs/customizing_dashboards.md but there isn't a collection/conditional option for
Field::HasMany
- only show the certain has_many collection in the view, in this case it'd be
admin/users/show.html.erb
. This is probably possible, but seems really messy to do so here - tried filtering in the admin/users_controller but i believe the controller only gives me the
requested_resource
and not the sub objects on that resource
Does anyone know how I could only show certain has_many objects in an administrate dashboard?