RailsAdmin:多态类型作为自定义过滤器

时间:2014-05-26 16:42:24

标签: ruby-on-rails ruby ruby-on-rails-4 polymorphism rails-admin

鉴于此模型,

class Flat < ActiveRecord::Base
  belongs_to :owner, polymorphic: true
end

在RailsAdmin中,我想添加一个owner_type过滤器。我该怎么办?

1 个答案:

答案 0 :(得分:1)

似乎对于所有关联字段,默认情况下都会关闭过滤。您需要做的就是重新打开它。

class Flat < ActiveRecord::Base
  belongs_to :owner, polymorphic: true

  rails_admin do
    list do
      filters [:owner_type] # if you'd like an owner_type filter by default
      field :owner_type do
        filterable true # allow owner_type to be filtered on
      end
    end
  end
end