Browse files

`initialize_on_precompile` is not used anymore.

  • Loading branch information...
1 parent 383842d commit 2d5a6de4e227ee97ccbea691c69728b7e31bf678 @hone hone committed Jun 4, 2013
19 guides/source/
@@ -419,17 +419,6 @@ The rake task is:
$ RAILS_ENV=production bundle exec rake assets:precompile
-For faster asset precompiles, you can partially load your application by setting
-`config.assets.initialize_on_precompile` to false in `config/application.rb`, though in that case templates
-cannot see application objects or methods. **Heroku requires this to be false.**
-WARNING: If you set `config.assets.initialize_on_precompile` to false, be sure to
-test `rake assets:precompile` locally before deploying. It may expose bugs where
-your assets reference application objects or methods, since those are still
-in scope in development mode regardless of the value of this flag. Changing this flag also affects
-engines. Engines can define assets for precompilation as well. Since the complete environment is not loaded,
-engines (or other gems) will not be loaded, which can cause missing assets.
Capistrano (v2.15.1 and above) includes a recipe to handle this in deployment. Add the following line to `Capfile`:
@@ -570,16 +559,8 @@ In `config/environments/development.rb`, place the following line:
config.assets.prefix = "/dev-assets"
-You will also need this in application.rb:
-config.assets.initialize_on_precompile = false
The `prefix` change makes Rails use a different URL for serving assets in development mode, and pass all requests to Sprockets. The prefix is still set to `/assets` in the production environment. Without this change, the application would serve the precompiled assets from `public/assets` in development, and you would not see any local changes until you compile assets again.
-The `initialize_on_precompile` change tells the precompile task to run without invoking Rails. This is because the precompile task runs in production mode by default, and will attempt to connect to your specified production database. Please note that you cannot have code in pipeline files that relies on Rails resources (such as the database) when compiling locally with this option.
You will also need to ensure that any compressors or minifiers are available on your development system.
In practice, this will allow you to precompile locally, have those files in your working tree, and commit those files to source control when needed. Development mode will work as expected.
4 railties/lib/rails/application.rb
@@ -207,9 +207,7 @@ def watchable_args #:nodoc:
# Initialize the application passing the given group. By default, the
- # group is :default but sprockets precompilation passes group equals
- # to assets if initialize_on_precompile is false to avoid booting the
- # whole app.
+ # group is :default
def initialize!(group=:default) #:nodoc:
raise "Application has been already initialized." if @initialized
run_initializers(group, self)
1 railties/lib/rails/application/configuration.rb
@@ -61,7 +61,6 @@ def initialize(*)
@assets.cache_store = [ :file_store, "#{root}/tmp/cache/assets/#{Rails.env}/" ]
@assets.js_compressor = nil
@assets.css_compressor = nil
- @assets.initialize_on_precompile = true
@assets.logger = nil
12 railties/test/application/assets_test.rb
@@ -376,18 +376,6 @@ class ::PostsController < ActionController::Base ; end
assert_equal "Post;\n",["#{app_path}/public/assets/application-*.js"].first)
- test "assets can't access model information when precompiling if not initializing the app" do
- app_file "app/models/post.rb", "class Post; end"
- app_file "app/assets/javascripts/application.js", "//= require_tree ."
- app_file "app/assets/javascripts/xmlhr.js.erb", "<%= defined?(Post) || :NoPost %>"
- add_to_config "config.assets.digest = false"
- add_to_config "config.assets.initialize_on_precompile = false"
- precompile!
- assert_equal "NoPost;\n",["#{app_path}/public/assets/application-*.js"].first)
- end
test "initialization on the assets group should set assets_dir" do
require "#{app_path}/config/application"

4 comments on commit 2d5a6de


Is this in rails 4? Is there a changelog entry so that I know what to do?

Ruby on Rails member

@bogdan if you look right under the commit message, it says 'master.' So this commit is slated to be in Rails 4.1.


ok thanks.


here is a workaround for this commit :/

the post is about passing a dummy database config while precompiling:

bundle exec rake RAILS_ENV=staging DATABASE_URL=mysql2://none:none@ assets:precompile
Please sign in to comment.