1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #10833 from hone/remove_initialize_on_precompile

`initialize_on_precompile` is not used anymore.
This commit is contained in:
Guillermo Iguaran 2013-06-13 19:22:57 -07:00
commit 90a6059dd2
4 changed files with 1 additions and 35 deletions

View file

@ -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 file

@ -207,9 +207,7 @@ module Rails
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 file

@ -61,7 +61,6 @@ module Rails
@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 file

@ -376,18 +376,6 @@ module ApplicationTests
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)