在 rails_admin 关联中更改类似查询
Changing like query in a rails_admin association
我正在使用 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
我只想搜索姓名。可能吗?
您可以配置为:
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 了解更多信息。
我正在使用 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
我只想搜索姓名。可能吗?
您可以配置为:
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 了解更多信息。