Building an Idiot-Proof Environment Indicator in Ruby on Rails

We’ve all been there: you’re testing a new feature, changing data, and suddenly realize you’re in production, affecting real users. At Unagi, after a few scares, we decided to implement a simple and reusable solution to prevent this from happening again: a fixed visual frame that tells you which environment you’re in

The idea is straightforward: show a striking border on all screens when the app runs in staging. But we wanted to do it elegantly, without cluttering layouts or adding repetitive logic. Here’s how we solved it using Ruby on Rails tools: `yield`, a helper, and `content_for`.

An orange frame indicating staging environment

How we implemented it

First, we created a helper that defines the border content only if we’re in staging. We used `content_for` so the main layout can render it wherever we want.

module ApplicationHelper
  def environment_indicator
    return unless Rails.env.staging?
    content_for(:environment_indicator) do
      tag.div('', class: 'environment-border)
    end
  end
end

We also defined the CSS styling in our application stylesheet to keep the styling concerns separate:

.environment-border {
  position: fixed;          /* Stays in place when scrolling */
  inset: 0;                 /* Covers entire viewport (top: 0, right: 0, bottom: 0, left: 0) */
  border: 5px solid orange; /* Orange border for high visibility */
  pointer-events: none;     /* Allows clicks to pass through without affecting user interaction */
  z-index: 9999;            /* Ensures it appears above all other elements */
}

Then, in the application layout, we added a `yield` for that content. This way, the border appears only when the helper has been executed.

<!-- app/views/layouts/application.html.erb →
<%= yield :environment_indicator %>
<!-- the rest of the layout →
<%= yield %>

Finally, we call the helper wherever makes most sense for your app. In our case, we put it in the layout, but you could do it in a base controller or a shared partial.

<!-- app/views/admin/users/index.html.erb →
<%= environment_indicator %>

The result? An orange border in staging that’s impossible to ignore, and zero impact on production. Plus, the solution is easy to test, maintain, and extend to other uses.

An orange frame indicating staging environment

What we learned

Sometimes the best solution is the simplest one. Leveraging helpers and `content_for` allowed us to add a visual indicator without breaking the app’s structure or introducing hacks. Most importantly: users won’t receive notifications like “testing123” anymore.

Has something similar happened to you? Do you have other tricks to differentiate environments? Leave your comment and, if this helped you, give it some claps.