简体   繁体   English

Rails_admin宝石过滤器has_many通过关联

[英]Rails_admin gem filter has_many through association

I'd like to be able to use the "Add Filter" dropdown so admins can search for posts that have been flagged a particular name. 我希望能够使用“添加过滤器”下拉菜单,以便管理员可以搜索已被标记为特定名称的帖子。

My Post model 我的帖子模型

class Post < ActiveRecord::Base
    belongs_to :user
    has_many :post_flags
    has_many :flags, through: :post_flags

config/initializers/rails_admin.rb 配置/初始化/ rails_admin.rb

config.model 'Post' do
    exclude_fields :rank, :embedded_url, :attached_picture, :updated_at

    object_label do
        "#{bindings[:post].user.name}"
      end

    list do
      field :text_content
      field :created_at
      field :user_id
      field :likes_number
      field :post_flags 
    end
 end

I've tried adding "searchable" to the field :post_flags to no avail. 我尝试将“可搜索”添加到字段:post_flags无济于事。 Any help would be much appreciated. 任何帮助将非常感激。

截图

I'm currently trying to work through a similar problem. 我目前正在尝试解决类似的问题。

Adding the following to your rails admin config should allow you to add a post_flag filter: 将以下内容添加到rails admin配置中,应该可以添加post_flag过滤器:

field :post_flags do
  searchable :name
end

However, you will get an SQL error when when you try to use the search filter. 但是,当您尝试使用搜索过滤器时,会出现SQL错误。

We may have to hack RailsAdmin's MainController. 我们可能需要破解RailsAdmin的MainController。 Checkout this post: http://blog.endpoint.com/2013/07/hasmany-filter-in-railsadmin.html 查看此帖子: http : //blog.endpoint.com/2013/07/hasmany-filter-in-railsadmin.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM