/ ruby

My favourite Ruby on Rails engines

Ruby on Rails Engines is one of the most powerful and underestimated features. It distinguishes Rails from other web frameworks.

What engines?

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:

  1. Sidekiq - background jobs
  2. Blazer - business intelligence
  3. Lookbook - UI components previews
  4. Flipper - Feature toggles
  5. Split - A/B testing
  6. PGHero - PostgreSQL monitoring
  7. FastEntry - cache previewer
  8. GraphiQL - GraphQL IDE

1) Sidekiq

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.

Sidekiq

2) Blazer

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.

Blazer

3) Lookbook

I found this recently.

If you use ViewComponents to build UI elements instead of Action View Helpers, you should use it. It builds on top of previews and wraps them in Storybook like interface.

However, if you have ever tried to set up Storybook and React components, you have spent A LOT of time on it.

This gem takes about 10 minutes to set up, and the rest is just writing simple previews Ruby classes.

Lookbook

4) Flipper

Flipper provides infrastructure and UI for Feature toggle.

I have written before how to integrate with React - here.

Flipper

Flipper has a paid version with features like permissions and audit history.

5) Split

Split provides infrastructure for A/B testing.

There are a lot of SaaS tools to do so; however, they are slowing your pages, cost a lot and take time integrate.

Split

6) PGHero

It provides a performance dashboard PostgreSQL. It tells you things like - slow queries, unused indexes, table/index sizes, and more.

It comes from ? Instacard, which makes also Blazer and other wonderful open source projects.

PGHero

7) FastEntry

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.

Fast Entry

8) GraphiQL

Last but not least. GraphiQL is IDE for GraphQL. This engine provides quick setup and integration.

GraphiQL

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

gem "blazer"

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

Note: 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 ?

Conclusion

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 ?

If you have any questions or comments, you can ping me on Twitter or Mastodon.