Simple Dark Features in Rails
Maybe I am too simple minded but I had a "ah-ha moment" when trying to roll out features dark. Consider the following code:
# application_helper.rb
module ApplicationHelper
def dark_feature
yield unless Rails.env.production?
end
end
I can now take this very simple block and apply it to a view:
# some random .haml file
- dark_feature do
%h1 Lol you can't see me in production lol
The above H1 tag will not render in production until the block is removed. Once the feature is ready, you can remove the block.
Is this too good to be true? Am I missing something? This was just something I was trying out pure experimentation. Even in a more complex example (say rendering data set in a controller), the feature still remains dark. There is obviously gaps though. I'd be interested to see other people's thoughts
Written by Bryan Mikaelian
Related protips
2 Responses
Nice tip!
This seems a good way to deploy feature flags! http://blog.travis-ci.com/2014-03-04-use-feature-flags-to-ship-changes-with-confidence