March 24, 2020
Gabriel Martin
Tags:
Sometimes you want the ability to flip a feature on or off, or only give certain users access to new features in your application. Maybe you want to get user feedback before the final release? Maybe you want the ability to revert to the previous functionality with a single command.
With the Rollout Gem, this type of functionality is extremely easy and straight forward to set up in a Rails application.
Rollout allows you to enable or disable features without having to revert changes in the repository or promote different branches to production.
It does this by saving a “feature flag” in Redis which is either on or off. You can enable this feature flag globally, on a per-user basis or toggle the feature on and off for specific groups of users.
In order for Rollout to work, we need to have a Redis client set up in our application. I’ll walk through how I set up Redis for the demo app I created for this write-up. But first, let me show you what the app is.
The demo app is a very simple to-do app. A user can create and delete todos, and mark them as complete.
As mentioned above, Rollout uses Redis to store the state of feature flag. So let’s set that up.
Create an env file and add the key for the Redis URL. Here’s what I did for local development.
Create the file.
‍
‍
Next, I added an initialization file for Redis
‍
and add this to that file.
‍
Right on. Now that Redis is set up, let’s see how you can implement and use Rollout.
I’m going to add a feature that allows a user to mark a todo as important. The only thing here is that I’m going to “wrap” this feature markup in Rollout so I can turn it on or off extremely. Let’s set up Rollout first.
‍
‍
‍
You should get something back like this.
‍
‍
Rollout is now ready to use!
‍
‍
You can see that I’ve wrapped the toggle important link in an if statement.
‍
‍
‍
Without this feature enabled, the app looks and performs the same as before the new code was added.
If we want to activate this feature, all we have to do is open up the rails console and run
‍
‍
‍
The great thing about this is that everything happens in a live environment. We don’t need to push a different branch if, for whatever reason, this new feature needs to be disabled, or restart any dynos to see the changes take effect.
‍
‍
Here is a short clip of all this in action.
There’s more to Rollout than just flipping a single feature on or off. Like I said before, you can enable features for specific users or place a bunch of users into groups (user testing) and enable features for the whole group. Be sure to check out the Rollout Docs to see how this additional functionality works.
‍