Nathan Long
Nathan Long

Reputation: 126122

In rails_admin, how can I filter based on the presence of an association id?

In rails_admin, I've got a list of cities. Some have a numeric state_id and some have a nil. I want my cities list view to let me filter based on whether that field is filled or blank.

How can I do that?

This raises an exception:

config.model 'City' do
  list do
    filters [:state_id]
    ...

... because rails_admin can't find "city_id" among its list of "filterable fields", even though it's one of the displayed fields.

Upvotes: 2

Views: 1170

Answers (1)

Nathan Long
Nathan Long

Reputation: 126122

You have to set the field as filterable explicitly.

config.model 'City' do
  list do
    field :state_id do
      filterable true
    end

With that, I no longer needed the filters setting.

Upvotes: 2

Related Questions