If you work with Ruby on Rails on a web application already released to production,
you surely have one browser tab on the prod app, and another one on
You may already have tried to reproduce a bug wondering why the
debugger command won’t
work just to realize five long minutes later that you were on the
Here is a trick to display the current
git branch you are working on in your development
browser tab. That way, your eye will catch on the orange badge and figure out quicker where
you are. Plus you get a nice benefit of knowing the feature context.
# app/helpers/application_helper.rb module ApplicationHelper def branch_info branch_name = `git rev-parse --abbrev-ref HEAD` content_tag :li do content_tag :p, :class => "navbar-text" do content_tag :span, branch_name, :class => "label label-warning" end end end end
This helper is ready to be used in your bootstrap top bar menu, inside a
<!-- app/views/layout/application.html.erb --> <div class="nav-collapse collapse"> <ul class="nav"> <%= branch_info if Rails.env.development? %> </ul> </div>
You will get a nice orange badge in the top bar of your web application reminding you that:
- You are in your
- Which feature branch you are working on.
Before coming with the shell approach, I was previously using the gem
repository = Grit::Repo.new(Rails.root) branch_name = repository.head.name
But I figured out that I just needed the branch name, so including a gem was a bit of overhead!
What about you? Which trick do you use in the
development environment? Have you tried