RailsAdmin - custom filter settings

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

You can filter your model based on the current columns existing in this model (id, created_at, etc.).

I want to add custom filters for associations.

For instance:

When I study the Cities model, I want to show only cities with one or more projects.

I could do this by adding a new column to the cities named has_projects as a boolean that will be set to true when there are 1 or more related projects, but I believe there should be a cleaner way to create my own custom filters

+6
source share
2 answers

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

I used belongs_to for the association, for example:

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

And in the form of a list added:

 list do filters [:partner_id] ... end 
+2
source

Having recently looked at docs recently, I don’t think that the functionality for this exists more elegantly.

-1
source

Source: https://habr.com/ru/post/903385/


All Articles