Where to define Rails app's version number [closed] Where to define Rails app's version number [closed] ruby ruby

Where to define Rails app's version number [closed]


I will reply my own question, I was not able to find a better answer.

Since Rails application is basically MySite::Application I thought app's version should be accessed by MySite::Application::VERSION so create :

config/initializers/version.rb

module MySite  class Application    VERSION = "0.0.4"  endend

or config/version.rb and require this file from config/application.rb


I add my own version to the Configuration class with an initializer:

app_version.rb

class Configuration  class << self    attr_accessor :app_version  end  @app_version = 0.72end

Within the app, I can pull the version:

@app_version = Configuration.app_version

Not sure why you want to use the version, but I often use versioning so I can see if a particularly version of code is actually running. In that case, I need every code revision to be reflected as a new version, so I use the Git version on my code and often just display the first few characters of it since that is likely unique enough to identify it.

@git_version = `git show --pretty=%H`[0..39]