[英]Search is case insensitive in development but sensitive in production environment
I have a search bar that performs a case insensitive search when running on localhost in the development environment, but when I push to Heroku and run in the production environment, the search is case sensitive. 我有一个搜索栏,当在开发环境中的localhost上运行时,它执行不区分大小写的搜索,但是当我推送到Heroku并在生产环境中运行时,搜索是区分大小写的。 Not sure what would cause this behavior.
不知道什么会导致此行为。
From app\\views\\layouts\\application.html.erb: 在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>
From app\\controllers\\ratings_controller.rb: 从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
From app\\models\\rating.rb: 从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
Thank you! 谢谢!
Heroku uses postgres, make sure you are using postgres in development as well. Heroku使用postgres,请确保在开发中也使用postgres。
use the ILIKE postgres case insensitive version of LIKE 使用ILIKE的LIKE不区分大小写的LIKE版本
combined_scope.where("name ILIKE ?", "%#{word}%")
http://www.postgresql.org/docs/9.1/static/functions-matching.html http://www.postgresql.org/docs/9.1/static/functions-matching.html
The key word ILIKE can be used instead of LIKE to make the match case-insensitive according to the active locale.
根据活动的语言环境,可以使用关键字ILIKE代替LIKE来使匹配不区分大小写。 This is not in the SQL standard but is a PostgreSQL extension.
这不是SQL标准,而是PostgreSQL扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.