您如何有效地在模型中的多个字段中进行搜索?
# user.rb model
def self.search(search, page)
paginate :per_page => 20, :page => page,
:conditions =>
['name like ? OR notes like ? OR code like ? OR city like ? OR state like ?,
"%#{search}%","%#{search}%","%#{search}%","%#{search}%","%#{search}%"
], :order => 'name'
这段代码对于几个字段来说都是可怕的,并且如果例如单词#1来自:name而单词#2来自:code,它不会返回结果。有没有更优雅的方式?