Ruby on Rails quick start
Integrate Meilisearch into your Ruby on Rails app.
Integrate Meilisearch into your Ruby on Rails app.
1. Create a Meilisearch project
Create a project in the Meilisearch Cloud dashboard. Check out our getting started guide for step-by-step instructions.
If you prefer to use the self-hosted version of Meilisearch, you can follow the quick start tutorial.
2. Create a Rails app
Ensure your environment uses at least Ruby 2.7.0 and Rails 6.1.
3. Install the meilisearch-rails gem
Navigate to your Rails app and install the meilisearch-rails
gem.
4. Add your Meilisearch credentials
Run the following command to create a config/initializers/meilisearch.rb
file.
Then add your Meilisearch URL and Default Admin API Key. On Meilisearch Cloud, you can find your credentials in your project settings.
5. Generate the model and run the database migration
Create an example Article
model and generate the migration files.
6. Index your model into Meilisearch
Include the MeiliSearch::Rails
module and the meilisearch
block.
This code creates an Article
index and adds search capabilities to your Article
model.
Once configured, meilisearch-rails
automatically syncs your table data with your Meilisearch instance.
7. Create new records in the database
Use the Rails console to create new entries in the database.
8. Start searching
Backend search
The backend search returns ORM-compliant objects reloaded from your database.
We strongly recommend using the frontend search to enjoy the swift and responsive search-as-you-type experience.
Frontend search
For testing purposes, you can explore the records using our built-in search preview.
We also provide resources to help you quickly build your own frontend interface.
Next steps
When you’re ready to use your own data, make sure to configure your index settings first to follow best practices. For a full configuration example, see the meilisearch-rails gem README.