How to get the version number of a Rails application in production

Lorenzo Sinisi bio photo By Lorenzo Sinisi Comment

A Rails application is usually deployed using tools like mina or capistrano. These tools tend to create a folder for each deployment and the name of the folder is usually a number indicating how many times the same app has been deployed in the same folder. Assuming that for each deployment the app changes, we could use this name/number as ‘version’ of the application.

There are at least 2 ways to get this version number:

Using split (takes advantage of the String class)

Rails.root.to_s.split(File::SEPARATOR).last

Using basename (takes advantage of File.basename)

Rails.root.basename.to_s

I prefer the second.

comments powered by Disqus