Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 476
Laurens Avatar asked Dec 08 '11 14:12

Laurens


1 Answers

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    
like image 111
dmukherjee Avatar answered Nov 03 '22 08:11

dmukherjee