Ruby on Rails Engines is one of the most powerful and underestimated features. It distinguishes Rails from other web frameworks.
Engines are embeddable applications that can be integrated into your Ruby on Rails application. They are distributed as regular Ruby gems with models, controllers, and views.
The UI that comes with engines is incredibly useful, and most engines can be set up within 10 minutes, saving months of integration of microservices and external SaaS tools.
Here are the top eight Ruby on Rails engines:
- ? Sidekiq - background jobs
- ? Blazer - business intelligence
- ?️ Lookbook - UI components previews
- ? Flipper - Feature toggles
- ? Split - A/B testing
- ?️ PGHero - PostgreSQL monitoring
- ⚡️ FastEntry - cache previewer
- ⚛️ GraphiQL - GraphQL IDE
Sidekiq is the de facto standard for background jobs in Ruby land. The engine provides a UI to monitor what is happening with your background jobs.
Blazer allows you to write SQL queries and build charts and dashboards from them, making it an excellent tool for business intelligence.
But even if you don't use it as a business intelligence tool. It is a great developer tool. It can help you see what is in your database in local or staging environments.
I found this recently.
This gem takes about 10 minutes to set up, and the rest is just writing simple previews Ruby classes.
Flipper provides infrastructure and UI for Feature toggle.
Flipper has a paid version with features like permissions and audit history.
There are a lot of SaaS tools to do so; however, they are slowing your pages, cost a lot and take time integrate.
It provides a performance dashboard PostgreSQL. It tells you things like - slow queries, unused indexes, table/index sizes, and more.
Do you know what is in your cache? FastEntry shows you this. Simple and useful.
I have found a secondary use for it in development. I use the same Redis instance for cache, Sidekiq, and application data storage. It shows you everything in this Redis instance.
How to setup and secure engines?
I mentioned that engines are easy to set up. But talk is cheap. Let me show you the code. ?
Let's install Blazer, as it is one of the more complex ones to set up.
Step 1: Add to Gemfile
Step 2: Bundle install & database setup
bundle install rails generate blazer:install rails db:migrate
Step 3: Mount to the Rails application
# config/routes.rb namespace :dev, constraints: Routes::AdminConstraint do mount Blazer::Engine, at: '/blazer' # ... other engines end
Routes::AdminConstraint ensures that this namespace is only available for certain users.
A simplified version can look something like:
module Routes::AdminConstraint extend self def matches?(request) return false if request.session[:user_id].blank? User.find(request.session[:user_id]).admin? end end
In Production: Have database as ENV variable
ENV["BLAZER_DATABASE_URL"] = "postgres://user:password@hostname:5432/database"
That's it, you have a business intelligence tool ?
Engines have saved me a lot of time (and use of external services) over the years. I'm constantly on the lookup for new useful ones ?