我正在使用rails admin并有两个简单的模型:
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
当我在管理区域添加新Spot时,它会正确显示下拉列表
但是当我开始输入时,它默认执行以下sql:
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
我想只搜索姓名。有可能吗?
答案 0 :(得分:3)
您可以将其配置为:
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
查看this wiki了解详情。