Skip to content

Instantly share code, notes, and snippets.

@mhulet
Created February 27, 2017 20:19
Show Gist options
  • Save mhulet/22b568c91a2daf37ebb49e77e480e9dc to your computer and use it in GitHub Desktop.
Save mhulet/22b568c91a2daf37ebb49e77e480e9dc to your computer and use it in GitHub Desktop.
Rails 4 / Algolia setup for indexing a model
# config/initializers/algolia.rb
AlgoliaSearch.configuration = {
application_id: ENV["ALGOLIA_APPLICATION_ID"],
api_key: ENV["ALGOLIA_ADMIN_API_KEY"]
}
gem "algoliasearch-rails", "~> 1.18.0"
# app/models/post.rb
class Note < ActiveRecord::Base
include AlgoliaSearch
algoliasearch sanitize: true, index_name: ENV['ALGOLIA_INDEX_NAME'] do
attributes :title, :content
searchableAttributes ['title', 'content']
tags do
[
"user_#{self.user.token}"
]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment