【问题标题】:Rails_admin gem filter has_many through associationRails_admin gem 过滤 has_many 通过关联
【发布时间】:2015-06-30 23:08:45
【问题描述】:

我希望能够使用“添加过滤器”下拉菜单,以便管理员可以搜索被标记为特定名称的帖子。

我的帖子模型

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

config/initializers/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

我尝试在 :post_flags 字段中添加“可搜索”,但无济于事。任何帮助将非常感激。

【问题讨论】:

    标签: ruby-on-rails ruby associations rails-admin


    【解决方案1】:

    我目前正在尝试解决类似的问题。

    将以下内容添加到您的 rails 管理配置应该允许您添加 post_flag 过滤器:

    field :post_flags do
      searchable :name
    end
    

    但是,当您尝试使用搜索过滤器时,会出现 SQL 错误。

    我们可能不得不破解 RailsAdmin 的 MainController。查看这篇文章:http://blog.endpoint.com/2013/07/hasmany-filter-in-railsadmin.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-27
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多