I have a validation that checks to make sure a checkbox is checked. When I try to precompile assets, it's hitting that validation, attempting to access the database, and failing (I'm deploying this app to Heroku, so this isn't going to work). This seems to be the culprit: https://github.com/rails/rails/blob/4-0-stable/activerecord/lib/active_record/attribute_methods.rb#L99
I do have config.assets.initialize_on_precompile = false in my application.rb. Here's a gist of the code I'm referencing: https://gist.github.com/willc0de4food/ca3c78f149dc5c425dcd
I also attempted to wrap the validation in ActiveSupport.on_load, with the same problem: https://gist.github.com/willc0de4food/3c48c5e4a2efb938b3b1
Do you have any initializers, which require Contract model?
Also as I understand you use rails 4.0.0_, if I'm right you do not need config.assets.initialize_on_precompile = false.
config.assets.initialize_on_precompile = false
Good to know, thanks.
The only initializer I have that might try, is the rails_admin initializer, but I'm telling it to blacklist the contract model: https://gist.github.com/willc0de4food/786b86ae8bc8bbe27eb9
hmm, elsewhere, some from your engines require 'Contractor' model on environment loading. I blame on rails_admin, but cannot say for sure. If you have complete rails examples, because by info which you have provided I cannot reproduce your problem. Default generated rails app with rails admin do not load any models.
Maybe Devise? Here's my Gemfile: https://gist.github.com/willc0de4food/7676a515262abd9acb28
Rails (like all of us 😉) is innocent until proven guilty. As @pftg mentions, it doesn't appear that this is Rails' issue. If you can reproduce this with vanilla Rails, please show that to us and we can re-open, but until then, this isn't a bug.
That's a pretty bare-bones app, and RAILS_ENV=production bundle exec rake assets:precompile is failing with the same error.
@willc0de4food I think you have point. I'm investigating why in your app acceptance validator breaks rake assets:precompile
just for notice, this only happens in your app.
Weird. Lol, so my Rails is the only one that's broken :[ Oh well. Just as an FYI, I can recreate this scenario every time on my machine: https://github.com/willc0de4food/checkbox_acceptance_test2
I created test case, so all models inherited from ActiveRecord::Base preloaded. So this is problem.
I can recreate after cloning his repo, cd into directory, run bundle install, then RAILS_ENV=production bundle exec rake assets:precompile
RAILS_ENV=production bundle exec rake assets:precompile
Unknown database 'checkbox_test2_production'
/Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:inblock in checkout'
/Users/mitchkett/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:inblock in connection'
The error does not get thrown if you run the rake command for development or test, just production.
I think, because eager_load! automatically invoked for production.
For now added fixed tests. Will continue investigation on eager loaded modules for production env.
Try to set config.assets.initialize_on_precompile = false in config/application.rb. http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
@miry see #11381 (comment)
@willc0de4food try this patch #11384
Are there instructions somewhere on the process of apply such a patch?
@willc0de4food replace config.eager_load = true with config.eager_load = true if config.eager_load.nil?
config.eager_load = true
config.eager_load = true if config.eager_load.nil?
I added PR #11389 with fixing bug for rake and fixing tests.
@miry that worked. No more error. I didn't realize you meant in the app's environment file :X
#11381: Ignore config.eager_load=true for rake
config.assets.initialize_on_precompile isn't supported in Rails 4 anymore 😁
looks like there is a reference to #11853
i also added a way to reproduce the issue. https://github.com/gugl/virtattr
any ideas for solutions?