Rails Initialization for an Application Extracted as an Engine

I was hoping to create a Rails application that can be used both as an Engine and as a standalone application.

In particular, I have a nascent application that I would like to connect to a client site, but ideally I would just like to use the application as a standalone system. However, if config / environment / *. Rb exists in a modified version of my application, I get a Uninitialized Constant error at a time when the application that I get depends on my engine starting up; Rails complains that the constant MyEngineModule :: Application cannot be found in the development.rb file, which, I think, is just a problem with the load order, since this does NOT happen when I run the standalone application. If I remove development.rb, the initial initializers that reference MyEngineModule :: Application will complain, so I tried to remove them, and all is well.

Great, except that the original application does not work, because its configuration is missing.

Is there any setting I can make for the initialization loading order (or loading paths in the definition of the Engine <Rails :: Engine class), which will prevent the initial configurations and initializers from loading in the engine context and allow me to leave them in place in the application context ?

The simple answer is probably this, but I feel stubborn and would like to know what it takes to make my original goal possible:

  • extract the code for MyEngine into the engine, delete the config / environment / * files and the config / initializers / * files and make the client application depend on it.
  • To make a “new” minimalist application depends on MyEngine and move the environment files and initializers to NewApp.

, - , , , , "" "", ? , , /*.rb , , .

+3
2

, , , /*. rb , :

if defined? CuteEngine::Application
  CuteEngine::Application.configure do
    config.whatever = something
  end
end

Rails:: Application . , .

+5

.

Rails 3.1 , , . , , , :

module CuteEngine
  class Engine < ::Rails::Engine
    isolate_namespace CuteEngine
  end
end

routes.rb :

mount CuteEngine::Engine, at: "/cuteness"

http://edgeguides.rubyonrails.org/engines.html#mounting-the-engine

http://railscasts.com/episodes/277-mountable-engines

+1

All Articles