How can I add autoload_paths to my Rails4 Engine?

Usually I add the following to config / application.rb to add autload_paths:

config.autoload_paths += Dir[Rails.root.join('app', 'poros', '{**}')]

How can I achieve the same in the engine? This seems to work when I just use the same code in application.rb in the host application, but I find it ugly that the code is not in the engine and it needs to be added to the host application for everything to work.

The only solution I found to add the download path through the engine is to add it to lib / engine / engine.rb:

config.to_prepare do
  Dir.glob(Rails.root + "../../app/poros/**/*.rb").each do |c|
    require_dependency(c)
  end
end

However, there is something fundamentally wrong with this, as this leads to problems when I restart the console (for example, it tells me that the constants are already defined or that the power block cannot execute the problem twice)

? ( , /, googled, )

+4
2

Rails:: Engine documentation Railtie :

class MyEngine < Rails::Engine
  # Add a load path for this specific Engine
  config.autoload_paths << File.expand_path("../lib/some/path", __FILE__)

  initializer "my_engine.add_middleware" do |app|
    app.middleware.use MyEngine::Middleware
  end
end
+6

poros - , .

, . , /. , , app/workers, autoload_paths.

+2

All Articles