Rails Version Management with Rails AppVersion

Rails AppVersion provides a standard way to handle version and environment information in Rails applications. It eliminates the need for custom version management solutions while providing useful conventions for error tracking, caching, and deployment verification.
Key Features
- Version information through
Rails.application.version
- Environment management via
Rails.application.env
- Version-aware response headers
- Cache key generation
- Console environment information
Basic Setup
# Gemfile
gem "rails_app_version"
# Terminal
bundle install
rails app:version:config
echo "1.0.0" > VERSION
Common Use Cases
Error Tracking:
Sentry.init do |config|
config.release = Rails.application.version.to_s
config.environment = Rails.application.env
end
Cache Management:
def index
Rails.cache.fetch("index-page-#{Rails.application.version.to_cache_key}") do
render :index
end
end
Version Headers:
# config/app_version.yml
staging:
middleware:
enabled: true
options:
version_header: X-Staging-Version
environment_header: X-Staging-Environment
Testing:
class VersionTest < ActiveSupport::TestCase
test "version information" do
assert_equal "1.2.3", Rails.application.version.to_s
assert_equal "1-2-3", Rails.application.version.to_cache_key
end
end
Version Management Options
- VERSION File (Recommended):
1.2.3
- YAML Configuration:
shared:
version: <%= Rails.root.join('VERSION').read.strip rescue '0.0.0' %>
revision: <%= Rails.root.join('REVISION').read.strip rescue (`git rev-parse HEAD`.strip rescue '0') %>
Accessing Version Details:
Rails.application.version.major # => 1
Rails.application.version.minor # => 2
Rails.application.version.patch # => 3
Rails.application.version.full # => "1.2.3 (abc123de)"
Environment Management:
Rails.application.env # => "staging"
Rails.application.env.production? # => false
Rails.application.env.staging? # => true
The gem is available at https://github.com/seuros/rails_app_version under the MIT License.
🔗 Interstellar Communications
No transmissions detected yet. Be the first to establish contact!
Related Posts
NoFlyList: How NoFlyList Optimizes Tag Queries
NoFlyList automatically detects your database type and uses specific optimization strategies to make tag queries blazingly fast.
NoFlyList: Custom Tag Screening with NoFlyList
Tag parsing seems simple until you handle real user input. Explore how NoFlyList's custom screening prevents malicious and spam tags.
NoFlyList: Choosing Between Polymorphic and Model-Specific Tags
Learn when to use polymorphic vs model-specific tags by building a blog platform. Understand the trade-offs and performance implications.