Home > Ruby on rails > Add tags with application version into your git branch and show it in view

Add tags with application version into your git branch and show it in view

You can look at “A successful branching model” for very good reference about layout of branches and worfklow on application in git.

According to this you add tags to commits in master branch. How to add tag with version?

1
git tag -a v1.4 -m 'my version 1.4'

Or we can add tag to existing commit by using commit hash:

1
git tag -a v1.2 -m 'version 1.2' 9fceb02

How can I add automatic version number in appliaction footer?

You can read tag from GIT and create global variable in Rails. This way you can use version number in any place. For example in layout.

Following example from http://stackoverflow.com/questions/9073446/where-do-you-store-your-rails-applications-version-number

Edit your application.rb file and place:

 Rails |  copy code |? 
1
if Rails.env.development?
2
  # Update version file from latest git tag
3
  File.open('config/version', 'w') do |file|
4
    file.write `git describe --tags --always` # or equivalent
5
  end
6
end
7
 
8
config.version = File.read('config/version')

Version file will be update every time you start your server – for example Unicorn. It will work only for development environment.

Now you can use this variable in your app view – it may by footer in app/views/layouts/application.html.haml (HAML in my example):

 Rails |  copy code |? 
1
%p.text-right #{MyAPP::Application::config.version}

Categories: Ruby on rails Tags: ,
  1. June 7th, 2014 at 11:09 | #1

    Hey there, Neat article. Likely to matter as well as your website with ie, could follow through? Firefox nevertheless would be the sector main in addition to a large aspect of people will omit the amazing composing for this reason dilemma.

  1. No trackbacks yet.
*