Laurens
Laurens

Reputation: 2420

RailsAdmin - Customizing your own filters

I'm using https://github.com/sferik/rails_admin to handle my admin interface.

It's possible to filter your model based on the current columns that exists in this model (id, created_at etc.)

I want to be able to add custom filters for associations.

For example:

When I'm exploring the "Towns" model I want to be able to show only towns that have one or more projects.

I could do this by adding a new column to towns, called has_projects as a boolean that will be set to true when there are 1 or more projects associated, but I feel there must be a cleaner way to make your own custom filters ?

Upvotes: 8

Views: 6129

Answers (1)

dmukherjee
dmukherjee

Reputation: 193

You can try using enum. See https://github.com/sferik/rails_admin/wiki/Enumeration

I used for belongs_to association, like following:

field :partner_id, :enum do
  enum do
    Partner.all.collect {|p| [p.name, p.id]}
  end
end

And in list view, added:

list do
  filters [:partner_id]
  ...
end    

Upvotes: 4

Related Questions