My app is working fine in localhost but it returns error 500: internal server error when i run in Heroku. It says, "We're sorry, but something went wrong. If you are the application owner check the logs for more information."
I have this under my routes.rb
get 'employees/showemployees'
resources :employees
and this, under my controller
def showemployees
str = params[:str]
render json: @employee = Employee.where('fname LIKE ? OR lname LIKE ? OR mname LIKE ? OR username LIKE ? or id LIKE ?',
"%#{str}%","%#{str}%","%#{str}%", "%#{str}%", "%#{str}%")
end
when i type http://localhost:3000/employees/showemployees?str=samplename it displays a json format of the record but when i type https://dtitdtr.herokuapp.com/employees/showemployees?str=samplename it will return the error 500
heroku run rake db:migrate
is already done yet still,
Found the answer!
i just added i
in LIKE
clause like this ILIKE
and have the code this way
render json: @employee = Employee.where('fname ILIKE ? OR lname ILIKE ? OR mname ILIKE ? OR username ILIKE ?',
"%#{str}%","%#{str}%","%#{str}%", "%#{str}%")
it won't work in localhost
but it works in heroku
. So when running this app in localhost
, the above code should have no i
before the LIKE
clause but when running this in heroku
, ILIKE
should be used instead of simple LIKE
because when using LIKE
clause only in heroku
, it will be case sensitive...
and by the way, id
was removed.