aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2011-09-04 20:56:47 -0500
committerGuillermo Iguaran <guilleiguaran@gmail.com>2011-09-04 20:56:47 -0500
commit3e62235c6c384775c0a12ba5683eba37fee8acd9 (patch)
treeeeb59514be6d7a80121936d237320e97cb04cf76 /railties/guides
parent0a2ea92efa52165d6b840f2f18382484388389d2 (diff)
downloadrails-3e62235c6c384775c0a12ba5683eba37fee8acd9.tar.gz
rails-3e62235c6c384775c0a12ba5683eba37fee8acd9.tar.bz2
rails-3e62235c6c384775c0a12ba5683eba37fee8acd9.zip
Add JavaScript and ERB section to Asset Guide
Diffstat (limited to 'railties/guides')
-rw-r--r--railties/guides/source/asset_pipeline.textile12
1 files changed, 12 insertions, 0 deletions
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
index 54464cdf4d..69b8d43f55 100644
--- a/railties/guides/source/asset_pipeline.textile
+++ b/railties/guides/source/asset_pipeline.textile
@@ -174,6 +174,18 @@ 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
+
+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:
+
+<plain>
+$('#logo').attr({
+ src: "<%= asset_path('logo.png') %>"
+});
+</plain>
+
+This writes the path to the particular asset being referenced.
+
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.