diff options
author | 簡煒航 <tonytonyjan@gmail.com> | 2012-12-04 11:22:12 -0800 |
---|---|---|
committer | 簡煒航 <tonytonyjan@gmail.com> | 2012-12-04 11:22:12 -0800 |
commit | c32978d4772304b8d5a4c9b51fc064b0076da1bb (patch) | |
tree | 743fa2e62a5037008fed1f0a5569e07ba56e11bd /guides/source | |
parent | 40e16121c05f10f9b75b6cd68c32092876142861 (diff) | |
parent | 52e1a424980013b00a153b5221473e8fef73fac2 (diff) | |
download | rails-c32978d4772304b8d5a4c9b51fc064b0076da1bb.tar.gz rails-c32978d4772304b8d5a4c9b51fc064b0076da1bb.tar.bz2 rails-c32978d4772304b8d5a4c9b51fc064b0076da1bb.zip |
Merge pull request #120 from tonytonyjan/patch
add a notice about loading assets in production mode
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/asset_pipeline.md | 19 |
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. |