Skip to content

Instantly share code, notes, and snippets.

@bigfive
Created December 1, 2014 04:52
Show Gist options
  • Save bigfive/160113ad0135691870c1 to your computer and use it in GitHub Desktop.
Save bigfive/160113ad0135691870c1 to your computer and use it in GitHub Desktop.
Rails 3 javascript asset path method
<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