Ruby on rails 搜索在开发中不区分大小写,但在生产环境中敏感
我有一个搜索栏,当在开发环境中的localhost上运行时,它执行不区分大小写的搜索,但是当我推到Heroku并在生产环境中运行时,搜索是区分大小写的。不确定什么会导致这种行为 从app\views\layouts\application.html.erb:Ruby on rails 搜索在开发中不区分大小写,但在生产环境中敏感,ruby-on-rails,heroku,production-environment,case-insensitive,dev-to-production,Ruby On Rails,Heroku,Production Environment,Case Insensitive,Dev To Production,我有一个搜索栏,当在开发环境中的localhost上运行时,它执行不区分大小写的搜索,但是当我推到Heroku并在生产环境中运行时,搜索是区分大小写的。不确定什么会导致这种行为 从app\views\layouts\application.html.erb: <form class="navbar-search pull-right"> <input type="text" class="search-query span3" placeholder="Find Som
<form class="navbar-search pull-right">
<input type="text" class="search-query span3" placeholder="Find Some Beers" name="search">
</form>
从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
谢谢大家! Heroku使用postgres,确保您在开发中也使用postgres 使用LIKE的ILIKE postgres不区分大小写版本
combined_scope.where("name ILIKE ?", "%#{word}%")
根据活动区域设置,可以使用关键字ILIKE而不是LIKE使匹配不区分大小写。这不在SQL标准中,而是PostgreSQL扩展
您是否在开发和生产中使用不同的数据库(例如,在开发中使用sqlite,在生产中使用postgres)?您使用的是哪种数据库?如果mysql请提供
选择表\u名称,从信息\u SCHEMA.COLUMNS中选择排序规则\u名称代码>用于表格评分。感谢您的帮助!在开发中切换到博士后,实现了ILIKE,现在效果很好。
combined_scope.where("name ILIKE ?", "%#{word}%")