Flipper Cloud

Get Started with Flipper Cloud on Rails

In addition to the steps outlined below, we have a fully functional example Rails application for you to peruse.

Step 1. Add Flipper to your app

It's recommended to persist your Flipper configuration locally with an adapter of your choice (e.g. ActiveRecord, Redis, Sequel, Mongo, or several other adapters). You can decide this later if you don't know which one you want now.

Gemfile
gem "flipper-active_record"

Run bundle to install.

$ bundle

If you're using the ActiveRecord adapter, you'll also need to generate the migrations and run them.

$ bin/rails g flipper:active_record
$ bin/rails db:migrate

You'll need to set the following ENV variable:

FLIPPER_CLOUD_TOKEN=<your-token-here>

Step 2. Use Flipper in your code

Use Flipper#enabled? in your app for anything you want to gate access to, such as rolling out new features, taking parts of your system offline for maintenance without disrupting everyone else, or many other reasons.

For example, here we check if the search feature of our app is enabled:

search_controller.rb
before_action :ensure_search_enabled

def ensure_search_enabled
  render :unavailable unless Flipper.enabled?(:search)
end

Now flip this feature on for different segments of your users:

# Enable a feature for everyone
Flipper.enable :search

# Enable a feature for a specific actor
Flipper.enable_actor :search, current_user

# Enable a feature for a group of actors
Flipper.enable_group :search, :admin

# Enable a feature for a percentage of actors
Flipper.enable_percentage_of_actors :search, 2

Read more about enabling features.

Step 3. Setup Webhooks for Production

We recommend syncing using webhooks for production. Using webhooks means that your app will only communicate with Cloud for writes (e.g. enable and disable), and is entirely disconnected from Cloud for reads (e.g. enabled?). This ensures that you are in control of your own availability, which is always a good practice for external services.

Add a new production webhook in Cloud (e.g. https://yourapp.com/_flipper). Once you create the webhook, you'll be taken to a page where you can get the webhook's secret. Update your ENV to set FLIPPER_CLOUD_SYNC_SECRET to this value.

FLIPPER_CLOUD_SYNC_SECRET=<webhook-secret>

If you're using Rails, we'll automatically mount the middleware to receive and act on these hooks at https://yourapp.com/_flipper when the FLIPPER_CLOUD_SYNC_SECRET environment variable is set.

Done

That's it. For a couple lines of code and a couple of clicks you get the full power of feature toggles with little to no performance impact.

Need Help?

We would be delighted to answer any questions or even setup a pairing session to help you get your application setup correctly. Shoot an email to support@flippercloud.io.

Start flipping features with Flipper Cloud to get support, audit history, finer-grained permissions, multi-environment sync, and all of your projects in one place.

Prefer our open source Cloudless option? You can also choose from several tiers to sponsor Flipper on GitHub.