When you have a new feature for your web application, you frequently want to manage how it is rolled out. It’s always a good idea to only release the feature to a small group of customers as this will help you make sure that it is working as it should. Additionally, you can use feature flags to manage access to applications capabilities at various plan levels.
The FeatureFlags Concern
It’s a good idea to create the feature flag capability as a concern so that it’s easy to use in multiple models.
An important detail to note is the
save parameter on
disable_feature. This lets us easily enable/disable multiple features without saving to the database after each one in
Adding FeatureFlags to a Model
With the concern, it’s easy to feature flags to a model.
Of course, this is a very simple Account model and I’m excluding any validation or error checking on account creation.
Checking for a Feature
Now that we have feature flags available, you can use them in your code to manage access to new features.
Checking for a Feature in a View
I’ve found it helpful to be able to check for a feature inside views to change the UI based on feature available. This is most easily handled via a helper.
Now, in a view, you can easily test for the feature.
Feature flags give you a nice way to control access to a particular new feature or capability in your app. Next week, we’ll look at remotely updating features in staging or production with Capistrano.