Skip to content

Feature Flags

Kevin edited this page Aug 24, 2024 · 4 revisions

What are feature flags?

Feature flags allow us to enable/disable and perform phased rollouts for new features on the site.

Adding a new feature flag

To add a new feature flag...

  1. Go to the db/seeds/feature_flags.rb file

  2. Add your feature flag name to the FEATURE_FLAGS array at the top of the file.

    Example:

    FEATURE_FLAGS = %i[my_feature].freeze
  3. Then, in your command line, run bin/rails db:seed

Using feature flags

Feature flags can be used anywhere, but you'll find yourself mostly using them in controllers and views.

Controller example:

class MyController < ApplicationController
  def show
   if Feature.enabled?(:my_feature, current_user)
     # do something
   else
     redirect_to home_path, notice: "Feature not enabled"
   end
end

View example:

<% if Feature.enabled?(:my_feature, current_user) do %>
  <p>My feature is enabled!</p>
<% end %>

Managing feature flags

Feature flags are enabled by default in development and review app environments. If you want to disable a feature flag in these environments or enable a feature flag in production, you'll have to do it through the UI in our admin section of the site.

  1. Visit /admin
  2. If you're in production, log into your admin account otherwise use our admin dummy account
  3. Got to Tools > Feature flags
  4. Find and click on your feature on the list

From here, you have a couple of options...

Enabling/disabling the feature for everyone

If the feature is not currently enabled, a "Fully enable" button will be present. "Clicking it will enable the feature for everyone on the site

Screenshot 2024-05-21 at 18 28 51

When a feature is already enabled, you can disable it at any point:

Screenshot 2024-05-21 at 18 30 17

Enabling the feature for a percentage of users

If you want to roll your feature out slowly to gauge feedback without affecting everyone on the site. You can enable it for a percentage of users using "Enabled for X% of actors".

Screenshot 2024-05-21 at 18 32 06