I have the following in my controller:
def autocomplete
spots = Spot.where("name LIKE ?", "%#{params[:term]}%")
render :json => spots.map(&:name)
end
Here is in my view:
<%= label_tag :term, "Term" %> <%= search_field_tag :term %>
...
$("input#term").autocomplete({
source: '<%= autocomplete_places_path %>',
minLength: 2,
delay: 500
});
Let's says I have this set of records:
| id | name | address |
| 1 | Stall A | Fruity Road |
| 2 | Stall B | Chinky Street |
| 3 | Restroom | White Garden |
When I search stall
, record 1
and 2
will show.
What I want to achieve is, when I search stall fru
, only record 1
will show. At the moment, no record is shown if I search this term.
I know I have to rewrite the query, but how do I go about it?
Many thanks.