我有一个搜索栏,在开发环境中的 localhost 上运行时执行不区分大小写的搜索,但是当我推送到 Heroku 并在生产环境中运行时,搜索是区分大小写的。不知道什么会导致这种行为。
从 app\views\layouts\application.html.erb:
<form class="navbar-search pull-right">
<input type="text" class="search-query span3" placeholder="Find Some Beers" name="search">
</form>
从 app\controllers\ratings_controller.rb:
def search
fff = Rating.search(params[:search])
@ratings_by_name = fff.paginate(:order => 'name ASC', :page => params[:page], :per_page =>10)
@ratings_by_score = fff.paginate(:order => 'score DESC', :page => params[:page], :per_page =>10)
end
从 app\models\rating.rb:
def self.search(query)
words = query.to_s.strip.split
words.inject(scoped) do |combined_scope, word|
combined_scope.where("name LIKE ?", "%#{word}%")
end
end
谢谢!