Last Updated: February 25, 2016
·
1.121K
· bryanmikaelian

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

2 Responses
Add your response

Nice tip!

over 1 year ago ·
over 1 year ago ·