aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/asset_pipeline.md
diff options
context:
space:
mode:
authorTony Jian <tonytonyjan@gmail.com>2012-12-05 02:39:49 +0800
committerTony Jian <tonytonyjan@gmail.com>2012-12-05 02:39:49 +0800
commit52e1a424980013b00a153b5221473e8fef73fac2 (patch)
tree743fa2e62a5037008fed1f0a5569e07ba56e11bd /guides/source/asset_pipeline.md
parent40e16121c05f10f9b75b6cd68c32092876142861 (diff)
downloadrails-52e1a424980013b00a153b5221473e8fef73fac2.tar.gz
rails-52e1a424980013b00a153b5221473e8fef73fac2.tar.bz2
rails-52e1a424980013b00a153b5221473e8fef73fac2.zip
add a notice about loading assets in production mode
Diffstat (limited to 'guides/source/asset_pipeline.md')
-rw-r--r--guides/source/asset_pipeline.md19
1 files changed, 18 insertions, 1 deletions
diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md
index fa4e714950..a4d6463035 100644
--- a/guides/source/asset_pipeline.md
+++ b/guides/source/asset_pipeline.md
@@ -100,7 +100,24 @@ In production, Rails precompiles these files to `public/assets` by default. The
When you generate a scaffold or a controller, Rails also generates a JavaScript file (or CoffeeScript file if the `coffee-rails` gem is in the `Gemfile`) and a Cascading Style Sheet file (or SCSS file if `sass-rails` is in the `Gemfile`) for that controller.
-For example, if you generate a `ProjectsController`, Rails will also add a new file at `app/assets/javascripts/projects.js.coffee` and another at `app/assets/stylesheets/projects.css.scss`. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as `<%= javascript_include_tag params[:controller] %>` or `<%= stylesheet_link_tag params[:controller] %>`.
+For example, if you generate a `ProjectsController`, Rails will also add a new file at `app/assets/javascripts/projects.js.coffee` and another at `app/assets/stylesheets/projects.css.scss`. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these controllers with lines such as `<%= javascript_include_tag params[:controller] %>` or `<%= stylesheet_link_tag params[:controller] %>`. Note that you have to set `config.assets.precompile` in `config/environments/production.rb` if you want to precomepile them and use in production mode. You can append them one by one or do something like this:
+
+ # config/environments/production.rb
+ config.assets.precompile << Proc.new { |path|
+ if path =~ /\.(css|js)\z/
+ full_path = Rails.application.assets.resolve(path).to_path
+ app_assets_path = Rails.root.join('app', 'assets').to_path
+ if full_path.starts_with? app_assets_path
+ puts "including asset: " + full_path
+ true
+ else
+ puts "excluding asset: " + full_path
+ false
+ end
+ else
+ false
+ end
+ }
NOTE: You must have an [ExecJS](https://github.com/sstephenson/execjs#readme) supported runtime in order to use CoffeeScript. If you are using Mac OS X or Windows you have a JavaScript runtime installed in your operating system. Check [ExecJS](https://github.com/sstephenson/execjs#readme) documentation to know all supported JavaScript runtimes.