My situation is a follows:
- I’m running application X
- X uses the gem “core”
- core extends the models of X with models A, B, C, D
In development this works perfectly. However when I run
(bundle exec) rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile
it fails on
** Execute environment
rake aborted!
uninitialized constant A
I tried to fix this issue by placing Rails.application.eager_load! before the Application.initialize! in environments.rb, but I’m afraid that only led to other errors.
Is there a way to include models from an engine in a gem BEFORE the assets:precompile?
I read something about requiring them one by one instead of eager_load all, but the path to the gem differs for every system.
engine.rb in “core”:
require 'paperclip'
module Core
class Engine < ::Rails::Engine
config.time_zone = 'Amsterdam'
config.encoding = "utf-8"
config.autoload_paths += %W(#{config.root}/lib/**)
config.generators do |g|
g.test_framework :rspec, :views => false, :fixture => true
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
end
initializer "core.load_app_instance_data" do |app|
Core.setup do |config|
config.app_root = app.root
end
app.class.configure do
#Pull in all the migrations from Commons to the application
config.paths['db/migrate'] += Core::Engine.paths['db/migrate'].existent
end
end
initializer "core.load_static_assets" do |app|
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
end
end
end
I prefer to put any fix in the core gem instead of application X. However if it’s not possible X is fine 🙂
Are you sure the “core” gem is loaded in the staging environment?