Stack Overflow-style Rails app versioning

Dec 23, 2016

tech

Hours ago, I was searching for ways to put a version number to my Rails app. SemVer is good but I want other way of versioning the app so I found this tutorial.
However, it didn’t work at all so I fixed it. Here’s the code:

config/initializers/version.rb

class LemonadePubSys::Application
    APP_VERSION = `git --work-tree="#{Rails.root}" log -1 --date=short --format="%ad-%h"`.gsub!(/-/,'.').strip
end

The difference between Khaja’s and mine is that I replaced shell command sed with the Ruby’s gsub! so that the command will work properly. I also added strip to remove newlines and the code was put in an initializer file since putting it into application.rb file won’t recognize it.

This is working for Rails 5 and above.

About the Author

I'm an 18-year old part-time freelance web developer from Davao City, Philippines. I also do graphic design and drawing during my free time. Currently studying ICT at Malayan Colleges Mindanao.