ruby - How can I determine the MD5 digest of a given asset in the Rails asset pipeline? -
i'm writing javascript-rich application in ruby on rails 3.1 project , using handlebars js templating framework. i'm trying figure out way dynamically append md5 digest of asset (generated during asset precompilation on production) tags within of handlebars template. i'm hoping there's hash asset path key , md5 digest value, haven't been able find one.
an ideal solution passing hash ruby javascript , defining handlebars helper automatically append md5 digest "src" attribute of asset.
has attempted similar? there must way utilize javascript templates in rails , reap benefits of asset fingerprinting.
as mentioned in comments, appending hash asset paths default part of asset pipeline.
in production, rails inserts md5 fingerprint each filename file cached web browser
you can read more fingerprinting in asset pipeline here. rails uses sprockets compile assets. fingerprinting comes part of sprockets process.
you can utilize sprockets' find_asset
method, passing in logical path asset sprockets::bundledasset
instance. example
[1] pry(main)> rails.application.assets.find_asset('application.js') => #<sprockets::bundledasset:0x3fe368ab8070 pathname="/users/deefour/sites/myapp/app/assets/javascripts/application.js", mtime=2013-02-03 15:33:57 -0500, digest="ab07585c8c7b5329878b1c51ed68831e">
you can phone call digest_path
on object it's md5
sum appended asset.
[1] pry(main)> rails.application.assets.find_asset('application.js').digest_path => "application-ab07585c8c7b5329878b1c51ed68831e.js"
with knowledge can create helper homecoming digest_path
asset in application, , phone call helper within .js.erb
files.
ruby-on-rails ruby md5 asset-pipeline handlebars.js
No comments:
Post a Comment