A simple and powerful feature flagging system for Ruby on Rails applications. RailsFlags provides an easy way to manage feature flags with support for multiple storage backends.
- Multiple storage adapters (Redis, Memory)
- Simple and intuitive API
- Thread-safe operations
- Configurable default states
- Support for flag metadata (descriptions, creation timestamps)
- Built-in admin interface for managing feature flags
Add this line to your application's Gemfile:
gem "rails_flags"
And then execute:
bundle install
RailsFlags can be configured with different adapters based on your needs:
# config/initializers/rails_flags.rb
RailsFlags.configure do |config|
config.adapter = RailsFlags::Adapters::MemoryAdapter.new
end
# config/initializers/rails_flags.rb
RailsFlags.configure do |config|
config.adapter = RailsFlags::Adapters::RedisAdapter.new(
host: "localhost",
port: 6379
)
end
Add this to your config/routes.rb
:
Rails.application.routes.draw do
mount RailsFlags::Engine => "/rails_flags"
end
Access the admin interface at /rails_flags/admin
to:
- View all feature flags
- Create new feature flags
- Enable/disable flags
- Delete feature flags
# Register a new feature flag (disabled by default)
RailsFlags.register(
:new_feature,
enabled: false,
description: "Awesome new feature"
)
# Register an enabled feature flag
RailsFlags.register(
:another_feature,
enabled: true,
description: "Another awesome feature"
)
# Check if a flag is enabled
if RailsFlags.enabled?(:new_feature)
# Feature code here
end
# Check if a flag is registered
RailsFlags.registered?(:new_feature)
# Enable a flag
RailsFlags.enable(:new_feature)
# Disable a flag
RailsFlags.disable(:new_feature)
# Delete a flag
RailsFlags.delete(:new_feature)
# Get all flags
all_flags = RailsFlags.all_flags
You can use feature flags in your views:
<% if RailsFlags.enabled?(:new_feature) %>
<!-- New feature content -->
<% end %>
- Simple in-memory storage
- Suitable for development and testing
- Data is lost when the application restarts
- Persistent storage using Redis
- Suitable for production use
- Provides atomic operations
- Requires Redis server
This gem supports multiple Rails versions (6.x, 7.x, and 8.x). We use Appraisal to test against different Rails versions.
To run the tests for all supported Rails versions:
bundle exec appraisal rspec
To run tests for a specific Rails version:
bundle exec appraisal rails-6 rspec # For Rails 6
bundle exec appraisal rails-7 rspec # For Rails 7
bundle exec appraisal rails-8 rspec # For Rails 8
- Fork it
- Create your feature branch (
git checkout -b feature/my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/my-new-feature
) - Create new Pull Request
The gem is available as open source under the terms of the MIT License.