【发布时间】:2013-07-19 23:14:48
【问题描述】:
我有一个这样的链接:
<%= link_to "All", cars_path(:search => :all) %>
当我点击他时,我会收到这个网址:
localhost:3000/cars?search=all
问题是,我在数据库中有 3 条记录,搜索链接中没有显示任何内容。
我的 cars_controller.rb 有索引:
@cars = Car.search(params[:search])
在 car.rb 模型中我有一个方法:
def self.search(search)
result = order('new DESC')
result = joins(:model => :brand).where('brands.title LIKE ? OR models.title LIKE ? OR status LIKE ?', "%#{search}%", "%#{search}%", "%#{search}%").order('new DESC') if search.present?
result
end
我有另一种方法,但我对此进行了限制,但仍然无法正常工作。
欢迎提出建议,谢谢!
【问题讨论】:
-
result.to_sql的结果是什么? -
我在日志中收到了这个:gist.github.com/stanmx/ce89c3f1703676094fdb
-
我必须为您指出问题吗? ;)
标签: ruby-on-rails search