algoliasearch-rails-example
repository on GitHub for a sample Rails app with Autocomplete and InstantSearch results pages.
Compatibility
This gem supports:- Ruby versions 2.5 and later
- Ruby on Rails versions 6 and 7.
Install
Install the gem directly:Gemfile
:
Configure
To configure the gem, create a new fileconfig/initializers/algoliasearch.rb
.
Add your Algolia credentials, the application ID and the API key.
You can find both in the Algolia dashboard.
Ruby
API client with custom settings
To customize settings such as timeout for the API client, you can make the Algolia gem use your instance of an API client. You can do this by setting theAlgoliaSearch.client
option to your initialized client:
Ruby
The algoliasearch
block
To index your model into Algolia,
include the AlgoliaSearch
module and the algoliasearch
block.
This block sets up your index and options.
If you want to use the default options, declare an empty block.
Ruby
Example configuration
To see a full configuration example, see the repository for the HN Search app.Method name and aliases
All methods injected by theAlgoliaSearch
module have the prefix algolia_
and are aliased to short names if they aren’t already defined by Rails:
Ruby