Nidhin S G
Nidhin S G

Reputation: 1695

Custom Filter for Active Admin

I need to make a custom filter in Active Admin page which goes 3 level deep in my Model function.

Workout Model

has_many: :workout_weeks

Workout Week Model

has_many: :workout_days
belongs_to: :workout

Workout Day Model

has_many: :workout_exercises
belongs_to: :workout_week

Workout Exercise Model

belongs_to: :workout_day

I want to write a custom filter in Workout Exercise Model's Active Admin Page which will sort Workout Exercise that belongs to a particular Workout

Upvotes: 1

Views: 2423

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52347

Let say you have name attribute in workouts table.

To have a dropdown selecton go with following:

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

Or, if you need a search box:

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

Under the hood AA is using ransack for filtering/searching, so consider taking a look into documentation for more info on how to build something advanced stuff.

Upvotes: 1

Related Questions