I am working on activeadmin filters. I have one filter which is not working. The filter:
filter :role, as: :select, collection: Common::User::ROLES
The scoped collection:
def scoped_collection
Common::User.where(role: Common::User::ROLES)
end
Roles are mentioned in the user.rb file:
ROLES = [ ADMIN, CUSTOMER, SYSTEM, LEAD]
But on using this filter I am getting the following error:
ActionView::Template::Error (undefined method `klass' for nil:NilClass):
1: insert_tag renderer_for(:index)
Do anyone have any idea why this filter is not working?
EDIT: I have noticed that the select filter with option equals is not working and the same filter with other options like contains, starts_with, ends_with is working.
The filter seems to be expecting an ActiveRecord relation since it's an association.
You can perhaps use the code you have in scoped_collection in the filter, and then get rid of the scoped_collection?
filter :role, as: :select, collection: Common::User.where(role: Common::User::ROLES)
Super late, but have you tried passing it as a proc?
filter :role, as: :select, collection: proc { Common::User::ROLES }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.