You can clone with
No one assigned
on new Rails 4.0.0.beta1 apps, Rails.application.config.assets.enabled is nil by default. Shouldn't it be true?
Steps to reproduce:
$ rails new testing
$ cd testing
$ bin/rails g controller test hello
$ echo "<%= 'Assets enabled' if Rails.application.config.assets.enabled %>" >> app/views/test/hello.html.erb
$ bin/rails server
Now visit localhost:3000/test/hello and you won't see "Assets enabled".
Apologies if this is now expected behavior.
If you print the Rails.application.config.assets hash, you see the enabled key is missing.
For some reason, it appears that Rails::Application::Configuration#assets is an undefined method, even though it should be an attr_accessor! Is there something wrong with my install, this seems like an odd problem.
E.g., I get:
NameError Exception: undefined method `assets' for class `Rails::Application::Configuration'
I am using ruby version 2.0.0p0.
@mjhoy can you put up a sample app on GitHub that illustrates the problem?
@senny Sure: https://github.com/mjhoy/asset_config_test
Running bin/rails s and opening http://localhost:3000/test/hello yields "Assets are not enabled" for me.
My problem appears to be that the asset configuration is not loaded properly; Rails.application.config.assets hits #method_missing here: https://github.com/rails/rails/blob/master/railties/lib/rails/railtie/configuration.rb#L89 rather than the attr_accessor. I'm assuming something is wrong with my own system; if you can reproduce the bug on my app, I can try writing up a test case.
I could reproduce the original issue (enabled is nil by default) in rails 4.0.0.rc1.
I think that this problem isn't in rails core. because of assets.class is Sprockets::Railtie::OrderedOptions.
According to sprockets-rails, assets.enabled is not set.
If we merge kennyj/sprockets-rails@89b7a59 to sprockets-rails, this issue is solved.
@kennyj So where does this get used? https://github.com/rails/rails/blob/master/railties/lib/rails/application/configuration.rb#L51 That's what's confusing me.
https://github.com/rails/rails/blob/master/railties/lib/rails/application/configuration.rb#L51 is not used.
According to https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L10-L18, in current implementation, Sprockets-rails overwrite config.assets. certainly, this is a little odd.
BTW: Is your second problem another problem (assets doesn't hit attr_accessor) ??
@kennyj Thank you, that answers my question and clears up my direct confusion — of course I'm still confused about why the hack exists! It seems, at the least, needlessly obfuscating. Why does the default asset pipeline silently overwrite asset configuration defaults in Rails core?
I've read many sources of rails and sprockets-rails since yesterday, and I think next things are true.
config.assets.(enabled / cache_store / initialize_on_precompile / logger)
And I guess that current behaviors are next things:
config.assets.compile = true
If a manifest file exists, assets_manifest accessor is available (sprockets/rails/helper.rb).
In production, compile = false / debug = false, Sprockets::Environment is not used, because of assets_environment is nil (sprockets/railties.rb).
In development, compile = true / debug = true, Sprockets::Environment is used. /assets mounts app.assets (Sprockets::Environment) (sprockets/railties.rb).
config.assets.enabled = false
Am I right ??? I'm sorry, if I'm wrong.
I think we should remove config.assets.(enabled / cache_store / initialize_on_precompile / logger) and fix a doc about asset pipeline.
wdyt, rails core team ?
@kennyj you're right, some options were removed to simplify the asset pipeline, we would like to add back initialize_on_precompile support in sprockets-rails before of final version of Rails 4
@guilleiguaran out of curiosity, what's the point of setting asset options in rails core if it will just be overwritten? is it slated to be removed?
Sorry to interrupt, but is there a workaround to this problem for rc1 ?
config.assets.enabled isn't used anymore then this issue can be closed :)