簡體   English   中英

活動管理員的自定義過濾器

[英]Custom Filter for Active Admin

我需要在Active Admin頁面中創建一個自定義過濾器,該頁面在我的Model函數中深入了3級。

鍛煉模型

has_many: :workout_weeks

鍛煉周模型

has_many: :workout_days
belongs_to: :workout

鍛煉日模型

has_many: :workout_exercises
belongs_to: :workout_week

鍛煉鍛煉模型

belongs_to: :workout_day

我想寫在鍛煉健身模式的Active管理頁面自定義過濾器,這將排序Workout Exercise屬於一個特定的Workout

假設您在workouts表中具有name屬性。

要進行下拉選擇,請執行以下操作:

filter :workout_name, as: :select, collection: -> { Workout.pluck(:id, :name) }

或者,如果您需要搜索框:

filter :workout_name_eq, as: :string, label: 'Your label'

在機管局內部,機管局正在使用ransack進行過濾/搜索,因此請考慮參考文檔以獲取有關如何構建高級內容的更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM