[英]Activeadmin: Collection not working on filter
我正在研究 activeadmin 過濾器。 我有一個過濾器不工作。 過濾器:
filter :role, as: :select, collection: Common::User::ROLES
范圍集合:
def scoped_collection
Common::User.where(role: Common::User::ROLES)
end
user.rb 文件中提到了角色:
ROLES = [ ADMIN, CUSTOMER, SYSTEM, LEAD]
但是在使用此過濾器時,我收到以下錯誤:
ActionView::Template::Error (undefined method `klass' for nil:NilClass):
1: insert_tag renderer_for(:index)
有誰知道為什么這個過濾器不起作用?
編輯:我注意到帶有選項 equals 的 select 過濾器不起作用,並且帶有其他選項(如 contains、starts_with、ends_with)的相同過濾器正在工作。
過濾器似乎期待 ActiveRecord 關系,因為它是一個關聯。
您也許可以在過濾器中使用您在 scoped_collection 中的代碼,然后擺脫 scoped_collection?
filter :role, as: :select, collection: Common::User.where(role: Common::User::ROLES)
超級晚了,但是您是否嘗試過將其作為 proc 傳遞?
filter :role, as: :select, collection: proc { Common::User::ROLES }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.