我在 activescaffold 列表页面中的正常搜索不起作用。
我有 ListLocations 表,其中有字段 id | list_id | wiki_location_id。我有以下模型关系
class List < ActiveRecord::Base
validates_presence_of :name
has_many :list_locations, :dependent => :destroy
end
class WikiLocation < ActiveRecord::Base
has_many :list_locations, :dependent => :destroy
end
class ListLocation < ActiveRecord::Base
belongs_to :list
belongs_to :wiki_location
def wiki_location_title
WikiLocation.find(wiki_location_id).title if wiki_location_id
end
def wiki_location_title= (title)
wiki_location = WikiLocation.find_by_title(title)
self.wiki_location_id = wiki_location.id if wiki_location
end
end
我的控制器是
class Admin::ListsController < Admin::AdminController
active_scaffold :list do |conf|
conf.columns = [:name, :list_order, :enabled]
conf.columns[:enabled].form_ui = :checkbox
conf.columns[:enabled].inplace_edit = true
list.sorting = {:list_order => 'asc'}
end
end
class Admin::WikiLocationsController < Admin::AdminController
active_scaffold :wiki_location do |conf|
conf.columns = [:title, :street]
list.per_page = 10
end
end
class Admin::ListLocationsController < Admin::AdminController
active_scaffold :list_location do |conf|
conf.columns = [:list, :wiki_location]
conf.columns[:list].form_ui = :select
conf.search.columns << :list
end
end
我还为 List_Locations 表中的 wiki_location 字段实现了 Search as you type(SAYT) 功能
我的观点看起来像
我已按照以下指定链接 Activescaffold 自动完成中的说明实现了自动完成功能
现在我的问题是当我在活动脚手架的列表页面中使用正常搜索时,我没有得到任何结果
我从控制台得到的查询是
SELECT `list_locations`.`id` AS t0_r0, `list_locations`.`list_id` AS t0_r1,
`list_locations`.`wiki_location_id` AS t0_r2, `list_locations`.`created_at` AS t0_r3,
`list_locations`.`updated_at` AS t0_r4, `lists`.`id` AS t1_r0, `lists`.`name` AS t1_r1,
`lists`.`list_order` AS t1_r2, `lists`.`enabled` AS t1_r3, `lists`.`created_at` AS
t1_r4, `lists`.`updated_at` AS t1_r5 FROM `list_locations` LEFT OUTER JOIN `lists` ON
`lists`.`id` = `list_locations`.`list_id` WHERE ((((`lists`.`id` LIKE '%museum%'))))
ORDER BY `list_locations`.`id` ASC LIMIT 15 OFFSET 0
它看起来像是在 lists.id 字段而不是 list.name 上搜索
为什么会这样。我怎样才能让它搜索list.name。我还需要搜索 wiki_locations.title 列。如何才能做到这一点。请帮忙。