Last active
January 2, 2016 10:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# views/posts/_post.html.erb | |
<% @posts.sort_by(&:created_at).reverse.each do |p| %> | |
<div class="panel panel-default"> | |
...... | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/assets/javascripts/posts.js.coffee | |
$ -> | |
$("#post_search").typeahead({ | |
name: "post" | |
remote: "/posts/autocomplete?query=%QUERY" | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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