Browse files

Add CoffeeScript example to JavaScript and ERB section

  • Loading branch information...
guilleiguaran authored and vijaydev committed Sep 5, 2011
1 parent 2451a68 commit abb0af197c17486511f30909c970c13a24701929
Showing with 7 additions and 1 deletion.
  1. +7 −1 railties/guides/source/asset_pipeline.textile
@@ -174,7 +174,7 @@ The more generic form can also be used but the asset path and class must both be
* +asset-url("rails.png", image)+ becomes +url(/assets/rails.png)+
* +asset-path("rails.png", image)+ becomes +"/assets/rails.png"+
-h5. JavaScript and ERB
+h5. JavaScript/CoffeeScript and ERB
If you add an +erb+ extension to a JavaScript asset, making it something such as +application.js.erb+, then you can use the +asset_path+ helper in your JavaScript code:
@@ -186,6 +186,12 @@ $('#logo').attr({
This writes the path to the particular asset being referenced.
+Similary, you can use the asset_path helper in CoffeeScript files with +erb+ extension (Eg.
+$('#logo').attr src: "<% asset_path('logo.png') %>"
h4. Manifest Files and Directives
Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain _directives_ -- instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if +Rails.application.config.assets.compress+ is set to +true+). By serving one file rather than many, the load time of pages are greatly reduced as there are fewer requests to make.

0 comments on commit abb0af1

Please sign in to comment.