Skip to content

Instantly share code, notes, and snippets.

@czepluch
Last active January 2, 2016 10:49
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 czepluch/8292086 to your computer and use it in GitHub Desktop.
Save czepluch/8292086 to your computer and use it in GitHub Desktop.
Autocompletion does not work. I have followed every step in this guide https://github.com/ankane/searchkick, but no luck.
# views/posts/_post.html.erb
<% @posts.sort_by(&:created_at).reverse.each do |p| %>
<div class="panel panel-default">
......
</div>
<% end %>
# views/posts/_search.html.erb
<%= form_tag("/users", method: "get", :html => { :class => "form-control"}) do %>
<%= text_field_tag :query, params[:query], :placeholder => "Søg", :class => "form-control", id: "post_search", autocomplete: "off" %>
<% end %>
class Post < ActiveRecord::Base
searchkick autocomplete: ['title']
belongs_to :user
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
end
# app/assets/javascripts/posts.js.coffee
$ ->
$("#post_search").typeahead({
name: "post"
remote: "/posts/autocomplete?query=%QUERY"
});
def autocomplete
render json: Post.search(params[:query], autocomplete: true, limit: 10).map(&:title)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment