作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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
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
最佳答案
尝试设置:
conf.columns[:list].search_sql = 'list.name'
关于ruby-on-rails - 如何在 ActiveScaffold Rails 3 中实现搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9529570/
我是一名优秀的程序员,十分优秀!