Skip to content

Instantly share code, notes, and snippets.

@andrewbredow
Created July 1, 2015 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewbredow/2a4364fc05eff8f933a7 to your computer and use it in GitHub Desktop.
Save andrewbredow/2a4364fc05eff8f933a7 to your computer and use it in GitHub Desktop.
jQuery UI AutoComplete
class IngredientsController < ApplicationController
def index
@ingredients = if params[:term]
Ingredient.where("name LIKE ?", "%#{params[:term]}%")
else
Ingredient.all.ordered
end
respond_to do |format|
format.html
format.json { render json: @ingredients, root: false }
end
end
end
$ ->
$(".autocomplete").autocomplete(
source: $(".autocomplete").data("path")
)
<div class="control-group name-column">
<%= f.label :name, class: 'control-label' %>
<div class="controls">
<%= f.fields_for :ingredient do |ingredient_form| %>
<%= ingredient_form.text_field :name, class: "autocomplete form-control", data: { path: admin_ingredients_path } %>
<% end %>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment