[英]Active Admin Rails4 custom filter with Ransack
我有資源訂單。 在我的管理面板(activeadmin)中,我需要一個布爾過濾器來獲取用戶具有特定角色的所有訂單。
在Order類中,我有一個這樣的范圍:
class Order
belongs_to :user
scope :client_only_in, -> { joins(:user).where('users.role = ?', 'client') }
end
在活動管理員order.rb我添加了以下過濾器:
filter :client_only, as: :check_boxes
使用rails 3(元搜索),我可以添加
search_method :client_only_in, type: :boolean
得到過濾器,但使用rails 4和Ransack我不知道該怎么做。
如果不將search_method
添加到訂單模型,我會收到錯誤消息
undefined method `client_only_in' for Ransack::Search
當我訪問索引管理員訂單頁面。
有幫助嗎?
我不知道如何做到這一點,但您總是可以根據用戶角色選擇要篩選的字段:
filter :users_role, as: :select, multiple: true, collection: proc{ User.uniq.pluck :role }
更新:啊,如果一個訂單belongs_to
一個用戶而不是它應該是:user_role
而不是:users_role
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.