Skip to content

fewerandfaster/flipper-rails-demo

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
app
 
 
bin
 
 
 
 
db
 
 
lib
 
 
log
 
 
 
 
 
 
tmp
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Flipper Rails Demo

Step by step instructions for using Flipper with Rails.

Step 1

Add flipper-cloud to the Gemfile.

flipper_version = '~> 0.25.0'
gem 'flipper-cloud', flipper_version
gem 'flipper-active_record', flipper_version
  • Run bundle to install.
  • Run bin/rails g flipper:active_record to generate migration for ActiveRecord adapter.
  • Run bin/rails db:migrate to run migration for ActiveRecord adapter.

Step 2

Create an account on flippercloud.io and get the token provided during signup.

Step 3

Configure cloud using ENV vars (preferred):

# required
FLIPPER_CLOUD_TOKEN=<your environment token here>

# optional (for production environment so you never poll cloud)
FLIPPER_CLOUD_SYNC_SECRET=<webhook sync secret>

Step 4

Test that everything works from console:

FLIPPER_CLOUD_TOKEN=<token-goes-here> bin/rails console
irb(main):006:0> Flipper.enabled?(:foo)
=> false
irb(main):007:0> Flipper.enable(:foo)
=> true
irb(main):008:0> Flipper.enabled?(:foo)
=> true

Or test that it works using this demo application:

git clone https://github.com/fewerandfaster/flipper-rails-demo.git
cd flipper-rails-demo
FLIPPER_CLOUD_TOKEN=<token-from-step-2-goes-here> bin/rails server

Open http://localhost:3000 in your browser.

Dotenv

This app also ships with dotenv so if you cp .env.example .env and tweak the token in .env, you won't need to export the FLIPPER_CLOUD_TOKEN env var for the Rails server or console.

More?

Head on over to the Flipper Cloud documentation.

Or check out the flipper README for links to more documentation and examples on the types of enablements and how to instrument and optimize your usage of Flipper.