ActiveScaffold Rails 3에서 검색 구현 방법
-
16-11-2019 - |
문제
ActiveScaffold 목록 페이지에서의 정상 검색이 작동하지 않습니다.
필드 ID가있는 ListLocations 테이블이 있습니다. 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 필드에 대한 유형 (SAYT) 기능을 구현했습니다.
내 견해가 처럼 보입니다.
아래의 지정된 링크 activalescaffold autocomplete
이제 나의 문제는 활성 스캐 폴드의 목록 페이지에서 정상적인 검색을 사용할 때 결과를 얻지 못한다
내 콘솔에서 얻은 쿼리는 입니다.
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
.
list.name 대신 lists.id 필드를 검색하는 것 같습니다.
왜 그렇게하는 이유는 무엇입니까? 어떻게 검색 할 수 있습니까? 또한 wiki_locations를 검색해야합니다. 티틀 컬럼도 있습니다. 어떻게이 작업을 수행 할 수 있습니까? 제발 도와주세요.
해결책
Try to set:
conf.columns[:list].search_sql = 'list.name'
제휴하지 않습니다 StackOverflow