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. Not sure what would cause this behavior.
From 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:
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:
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.
use the ILIKE postgres case insensitive version of LIKE
combined_scope.where("name ILIKE ?", "%#{word}%")
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. This is not in the SQL standard but is a PostgreSQL extension.