Peek::AltRoutes
Easily toggle alternate controllers and routes.
Things this peek view provides:
- A ready to go route constraint for switching controllers/views or routes
- A toggle button to quickly enable and disable the alternate routes
Installation
Add this line to your application's Gemfile:
gem 'peek-alt-routes
And then execute:
$ bundle
Or install it yourself as:
$ gem install peek-alt-routes
Usage
Add the following to your config/initializers/peek.rb
:
Peek.into Peek::Views::AltRoutes
You may provide a name
option to the Peek view to set the button display text:
Peek.into Peek::Views::AltRoutes, name: 'Site Redesign'
Add the following to your app/assets/javascripts/application.js
:
//= require peek/views/alt_routes
Add the following to your app/assets/javascripts/application.css
:
/*
*= require peek/views/alt_routes
*/
Use the peek_alt_routes?
route constraint as you see fit. In config/routes.rb
:
# Remember that Rails matches the first route it finds (top to bottom) so
# be sure to put any constrained routes before the open routes.
# Route group example:
constraints peek_alt_routes?: true do
get '/about', to: 'next_site#about'
get '/contact', to: 'next_site#contact'
end
get '/about', to: 'site#about'
get '/contact', to: 'site#contact'
# Single case example:
get 'new-site-only' to: 'new_site#only', constraints: { peek_alt_routes?: true }
# DRY routes using routing concerns ( >= Rails 4.0 ) example:
concern :static_pages do
get '/about, action: 'about'
get '/contact, action: 'contact'
end
scope controller: 'next_site', constraints: { peek_alt_routes?: true } do
concerns :static_pages
get '/help', action: 'help'
end
scope controller: 'site' do
concerns :static_pages
end
When to use this vs Flipper
- Flipper is a full featured gem that is supplementary to this gem.
- Prefer this gem only for cases when a full visual redesign is wanted. This gem only does quick user facing feature toggling better than flipper.
- Use flipper for multiple or non-visual feature toggles or when advanced roll out procedures are needed.
Notes
- Be sure to render the Peek bar in your alternate views so it may be disabled.
- Be sure to implement user security into your alternate controllers. Peek-alt-routes simply sets and checks a cookie for determining which routes to use.
- The
peek_alt_routes?
method is available in controllers as well should you need it.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request