class SearchController < ApplicationController
def autocomplete
@location=Location.find_by_sql("select * from locations where name like ?;",['%'+params[:term]+'%'])
render json: @location
end
end
I think query like this is not working as expected: select * from locations where name like '%XXXX%';
Neither can I wrote code like this: @location=Location.find_by_sql("select * from locations where name like '?';", the function will fail to recognize the params
So how could I implement such keywords filtering queries?