Hi Guys…

Today I would like to give you a basic understanding of Rollout Gem in this blog post.

So first of all,

What Rollout Gem Can Do?

Rollout gem gives us control on deploying a new feature to the Staging/Production environment for the specific number of users. By using Rollout gem, the user has control on the feature enabling/disabling to a specific user or group of users or percentage of users. We will learn how to roll out a feature to a few users before it reaches out to the masses by using this gem.

How Do We Do That?

In short, simply we just wrap a conditional around some feature in your application, and then we trigger that conditional (or not) at runtime based on a configuration setting.

How Does It Work?

Basically, It uses Redis backend to manage which users are able to see which given feature. So make sure Redis is installed.

Add gems to the gem file

gem 'redis'

gem 'rollout'

Don’t forget to run bundle install to install the above gems

bundle install

Then setup rollout inside the initializers directory which is in the config. Make a new file called rollout_setup.rb in initializers directory.

Now, the documentation recommends using global variables, So first setup redis and then roll out in the rollout_setup file that we created.

$redis = Redis.new

$rollout = Rollout.new($redis)

And we might want to provide access to groups of users to access the feature. So, use define_group on rollout instance. Here, we have admins.

$rollout.define_group(:admins) do |user|

user.admin?

End

Now that we have rollout set up, we have to figure out which feature we have to roll out for the specific group of users. We are using the feature “send in email”

Here, only admins can see the link “send in email” see below image.

Rollout output1
Rollout Output2

On clicking the link, the page to enter email address opens and on clicking “send in email” button the list is sent on the email

Rollout Output 3

After that, wrap the feature code in the view with the if clause to check whether a user has access to the feature

$rollout.active?(:email, current_user)

Here, If the current_user is selected to access the feature then the feature code is executed.

Now we have to tell rollout to activate this feature for the defined group. We can do this from rails console or you can also do this through the rake task.

$rollout.activate_group(:email, :admin)

So, this will activate the feature for the given group

If we want to activate every user you can use: all that will activate all users because there is an all group set up by default i.e for all users

$rollout.activate_group(:email, :all)

Or we want to activate the feature for a single user

$rollout.activate_user(:email, User.find_by_name(“Leena”))

After activating the feature of email for Leena from the console, we can see the link “send in an email” in the below image.

Rollout output 4

We can activate a percentage of users

$rollout.activate_percentage(:email, 20)

Each of these methods has a deactivate version for removing the activation or you can remove all activation for the given feature

$rollout.deactivate_user(:email, User.first)

$rollout.deactivate_all(:email)

Read Also: Most useful Ruby on Rails Gems

About Rollout – Dashboard

We also have an interactive user interface for rollout gem called Rollout – Dashboard.

With Rollout-Dashboard, we can manage all of our features from a single dashboard and Monitor user’s feature distribution and usage while keeping an eye on deployment percentages.

To perform actions on rollout gem Rollout-Dashboard communicates with Rollout-Service via AJAX requests.

Click here for more details…

At BoTree Technologies, we build enterprise applications with our RoR team of 25+ engineers.

We also specialize in Python, RPA, AI, Django, JavaScript and ReactJS.

Consulting is free – let us help you grow!