Skip to main content
Check the 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.
This gem is compatible with:

Install

Install the gem directly:
Command line
Or add it to your Gemfile:
And run:
Command line

Configure

To configure the gem, create a new file config/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 the AlgoliaSearch.client option to your initialized client:
Ruby

The algoliasearch block

To send your model to Algolia, include the AlgoliaSearch module and the algoliasearch block. This block sets up your 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 the AlgoliaSearch module have the prefix algolia_ and are aliased to short names if they aren’t already defined by Rails:
Ruby
Last modified on June 12, 2026