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

爷,独闯天下 提交于 2019-12-11 02:34:47

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/26179848/in-rails-admin-how-can-i-filter-based-on-the-presence-of-an-association-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!