Feature flags for Ruby on Rails — safe rollouts with simple HTTP integration
Sign up at flagbit.anethoth.com to get your SDK key. The free tier includes 1,000 evaluations/day.
gem install httparty
require 'httparty'
require 'json'
module FlagBit
SDK_KEY = ENV['FLAGBIT_SDK_KEY']
URL = 'https://flagbit.anethoth.com/api/v1/evaluate'
def self.enabled?(flag_key, context = {})
resp = HTTParty.post(URL,
headers: { 'Content-Type' => 'application/json', 'X-SDK-Key' => SDK_KEY },
body: { flag_key: flag_key, context: context }.to_json,
timeout: 5
)
resp.parsed_response['value'] == true
rescue StandardError
false
end
end
# Rails controller concern
module FeatureFlags
extend ActiveSupport::Concern
private
def feature_enabled?(flag_key)
context = current_user ? { user_id: current_user.id.to_s, plan: current_user.plan } : {}
FlagBit.enabled?(flag_key, context)
end
def require_feature!(flag_key)
head :not_found unless feature_enabled?(flag_key)
end
end
# Controller usage
class DashboardController < ApplicationController
include FeatureFlags
before_action -> { require_feature!('new-dashboard') }, only: [:beta]
def index
if feature_enabled?('analytics-v2')
render :index_v2
else
render :index
end
end
end
# View helper
module ApplicationHelper
def feature_flag(flag_key, context = {}, &block)
capture(&block) if FlagBit.enabled?(flag_key, context)
end
end
# In ERB: <%= feature_flag('promo-banner') { render 'promo' } %>
Gate new Active Record models or controllers behind flags during schema migrations.
A/B test email templates by flagging which version of ActionMailer template to use.
Enable or disable background jobs without redeploying — useful during incidents.
Enable premium features per tenant using targeting rules based on organization ID.
Define flags in your FlagBit dashboard with targeting rules and rollout percentages.
Call the evaluate endpoint from your Ruby on Rails app with user context for targeted rollouts.
Enable, disable, or adjust rollouts in real-time. No redeployment needed.
FlagBit is a hosted API — no database tables in your Rails app, no gem dependencies, no self-hosting. Trade-off: network call vs. local DB query.
Yes — the view helper above lets you wrap any ERB block in a feature flag check.
Stub FlagBit.enabled? in RSpec: allow(FlagBit).to receive(:enabled?).with('flag-key').and_return(true)
Use Rails.cache.fetch with a TTL: Rails.cache.fetch("flag:#{key}", expires_in: 1.minute) { FlagBit.enabled?(key, ctx) }
Free tier includes 1 project, 10 flags, and 1,000 evaluations/day. No credit card required.
Get Your Free API Key