Integrate Metabase in Ruby on Rails

Today, I am proposing a very simple tutorial. I needed to integrate a Metabase dashboard in one of my applications and I realized there is no article which explains how to do that. So, ta-da!

Requirements

To follow this tutorial, you will need

  • a Metabase dashboard (read this article from my fellow Laurent Dogin to have yours set up in a few minutes)
  • a Ruby on Rails application (read this article by me if you need to set up one)

Enabling integration in Metabase

From your Metabase, click on the top right gear icon, then Admin. On the left menu select Embedding in other Applications. Toggle the button to have it saying Enabled. You will now get an Embedding API key. Save it for later.

Enable integrations on Metabase

Leave Metabase admin and select the dashboard you want to integrate. Click the sharing and embedding icon on the top right of your dashboard. Now select Embed this dashboard in an Application. Finally, click on the Publish button.

Integrate Metabase in Rails

In your Gemfile, add gem 'jwt' then run $ bundle install. If your application is deployed on Clever Cloud go to your application's console and under your application's menu go to the environment variables menu. If you deploy locally, use the gem figaro and edit your application.yml. Anyway you must add two environment variables

METABASE_SITE_URL: <your metabase url>
METABASE_SECRET_KEY: <the API key from metabase admin>

In the controller action where you want to integrate your metabase dashboard, add the following lines:

payload = {
          :resource => {:dashboard => <your dashboard number>},
          :params => { },
          :exp => Time.now.to_i + (60 * 10) # 10 minute expiration
    }
token = JWT.encode(payload, ENV["METABASE_SECRET_KEY"])
@iframe_url = ENV["METABASE_SITE_URL"] + "/embed/dashboard/" + token + "#bordered=true&titled=true"

Now in your view, add

<iframe
    src="<%= @iframe_url %>"
    frameborder="0"
    width="800"
    height="600"
    allowtransparency
></iframe>

You are all set. Just restart your application so the new environment variables are taken in consideration. Voilà, your application now has an integrated Metabase dashboard.

Blog

À lire également

Clever Cloud recognized by Gartner in its 2025 Magic Quadrant for Cloud-Native Application Platforms

Clever Cloud, a European Platform-as-a-Service (PaaS) provider, is proud to announce that it has been recognized as an Honorable Mention in Gartner’s latest Magic Quadrant for Cloud-Native Application Platforms, published on August 4, 2025.
Company Press

Developing Your Sylius Website with Monsieur Biz and Hosting it on Clever Cloud: A High-Performance Tailor-Made Solution

Sylius is an open-source e-commerce solution based on Symfony, renowned for its modularity and ability to support complex, custom architectures. Monsieur Biz specializes in building your site on Sylius, paired with high-performance hosting like Clever Cloud. Here's what you need to know.
Guests

Deploy your applications with Bun effortlessly on Clever Cloud

Bun revolutionizes the JavaScript ecosystem with its excellent performance, native TypeScript handling, and all-in-one approach. This open source alternative to Node.js/npm is gaining popularity among developers. We've streamlined its usage on Clever Cloud.
Company