Permalink
Browse files

`initialize_on_precompile` is not used anymore.

  • Loading branch information...
1 parent 383842d commit 2d5a6de4e227ee97ccbea691c69728b7e31bf678 @hone hone committed Jun 4, 2013
View
19 guides/source/asset_pipeline.md
@@ -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`:
```ruby
@@ -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:
-
-```ruby
-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.
View
4 railties/lib/rails/application.rb
@@ -207,9 +207,7 @@ def watchable_args #:nodoc:
end
# 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)
View
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
end
View
12 railties/test/application/assets_test.rb
@@ -376,18 +376,6 @@ class ::PostsController < ActionController::Base ; end
assert_equal "Post;\n", File.read(Dir["#{app_path}/public/assets/application-*.js"].first)
end
- 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", File.read(Dir["#{app_path}/public/assets/application-*.js"].first)
- end
-
test "initialization on the assets group should set assets_dir" do
require "#{app_path}/config/application"
Rails.application.initialize!(:assets)

4 comments on commit 2d5a6de

@bogdan

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

@steveklabnik
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.

@bogdan

ok thanks.

@snackycracky

here is a workaround for this commit :/ https://iprog.com/posting/2013/07/errors-when-precompiling-assets-in-rails-4-0

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

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