Created
December 1, 2014 04:52
-
-
Save bigfive/160113ad0135691870c1 to your computer and use it in GitHub Desktop.
Rails 3 javascript asset path method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
<% if File.exists? Rails.root.join('public/assets/manifest.yml') %> | |
window.railsAssetManifest = <%= raw YAML.load_file(Rails.root.join('public/assets/manifest.yml')).to_json %>; | |
<% else %> | |
window.railsAssetManifest = {}; | |
<% end %> | |
window.railsAssetPath = function(assetName){ | |
result = (!!window.railsAssetManifest[assetName] ? window.railsAssetManifest[assetName] : assetName); | |
return ('/assets/' + result); | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment