João Mateus João Mateus - 25 days ago 8
Ruby Question

Code works on local server but not on heroku

The below code searches for products on an app I'm building. In my local server the search can be made case insensitive but not on heroku

def index
if params[:q]
search_term = params[:q]
@products = Product.where("name LIKE ?", "%#{search_term}%")
else
@products = Product.all
end
end


how can i fix this? I need it to be case insensitive.

Many thanks in advance.

Answer

You could do something like:

search_term = params[:q].downcase

or

search_term = params[q:].upcase

thereby sanitizing the inputs.