aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2011-09-04 21:01:04 -0500
committerGuillermo Iguaran <guilleiguaran@gmail.com>2011-09-04 21:01:04 -0500
commita1dbd94b60ee4118e4706f7bb3a416fcc215e0b5 (patch)
tree56c8eb7339507f502a8a0bb4317a5090b2510661 /railties/guides
parent3e62235c6c384775c0a12ba5683eba37fee8acd9 (diff)
downloadrails-a1dbd94b60ee4118e4706f7bb3a416fcc215e0b5.tar.gz
rails-a1dbd94b60ee4118e4706f7bb3a416fcc215e0b5.tar.bz2
rails-a1dbd94b60ee4118e4706f7bb3a416fcc215e0b5.zip
Add CoffeeScript example to JavaScript and ERB section
Diffstat (limited to 'railties/guides')
-rw-r--r--railties/guides/source/asset_pipeline.textile8
1 files changed, 7 insertions, 1 deletions
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 69b8d43f55..fdb18651dc 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/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. application.js.coffee.erb):
+
+<plain>
+$('#logo').attr src: "<% asset_path('logo.png') %>"
+</plain>
+
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.