改变像rails_admin协会的查询 - Changing like query in a rails_admin association

- 此内容更新于:2016-02-01
主题:

我使用rails管理员和有两个简单的模型:当我添加一个新的点在管理区域,它显示了正确的下拉列表,字段出现的但是当我开始打字,它执行以下sql缺省情况下:我想只有搜索的名字。是可能的吗?

原文:

I am using rails admin and have two simple models:

class Spot < ActiveRecord::Base
    has_many :user_spots
end

class UserSpot < ActiveRecord::Base
    belongs_to :spot
end

RailsAdmin.config do |config|
    config.model UserSpot do
        exclude_fields :id, :created_at, :updated_at
    end
end

when I am adding a new Spot in the admin area, it shows the dropdown list correctly,

How the field appears

but when I start typing, it executes the following sql by default:

  Spot Load (0.6ms)  SELECT  `spots`.* FROM `spots` WHERE ((LOWER(spots.name) LIKE '%n%') OR (LOWER(spots.about) LIKE '%n%') OR (LOWER(spots.hours) LIKE '%n%') OR (LOWER(spots.location) LIKE '%n%') OR (LOWER(spots.call_info) LIKE '%n%') OR (LOWER(spots.website) LIKE '%n%') OR (LOWER(spots.menu) LIKE '%n%'))  ORDER BY spots.id desc LIMIT 30

I would like to search only for name. Is it possible?

解决方案:
您可以配置一样:检查这个wiki的更多信息。
原文:

You can configure the same as:

RailsAdmin.config do |config|
  config.model UserSpot do
    exclude_fields :id, :created_at, :updated_at
    list do
      field :about do
        searchable false
      end

      field :hours do
        searchable false
      end

      # Like this mark false all the fields you don't want to 
      # search. By default all fields are searchable.
    end
  end
end

Check this wiki for more information.