Skip to content

Instantly share code, notes, and snippets.

@Kerrick
Created May 30, 2012 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kerrick/2839458 to your computer and use it in GitHub Desktop.
Save Kerrick/2839458 to your computer and use it in GitHub Desktop.
Override how rails computes asset tags to work in multi-server deployments via git commits
# Override how rails computes asset tags to work in multi-server deployments via git commits
module ActionView
module Helpers
module AssetTagHelper
def rails_asset_id(source)
if asset_id = ENV["RAILS_ASSET_ID"]
asset_id
else
if @@cache_asset_timestamps && (asset_id = @@asset_timestamps_cache[source])
asset_id
else
path = File.join(ASSETS_DIR, source)
asset_id = File.exist?(path) ? `git log --format="%H" --max-count=1 #{path}`[0..12] : ''
if @@cache_asset_timestamps
@@asset_timestamps_cache_guard.synchronize do
@@asset_timestamps_cache[source] = asset_id
end
end
asset_id
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment