View
= text_field_tag :food_tokens
FoodsController
def search
@foods = Food.where("name LIKE ?" , "%#{params[:q]}%")
respond_to do |format|
format.json { render json: @foods.as_json(only: [:id, :name]) }
end
end
Routes
match '/search' => 'foods#search'
application.js
$(function() {
$('#food_tokens').tokenInput('/search.json', { crossDomain: false }
});
Output from /search.json
[{"id":"5","name":"Apple"},{"id":"6","name":"Burger"}]
When I start typing 'Apple' into the text field, I get the "No results" message.
Any insights?