ruby-on-railsruby-on-rails-4namespacesrails-enginesrails-generate

Rails 4 engine with nested namespace


I could not find a way to generate engines with nested namespaces under rails. Every time I do that, I basically have to edit and move around the generated files by hand. Is there really no support for nested namespaces in rails? Seems unlikely.

At the company we namespace everything like this: CompanyName::SerivceName::Module

So when I'm working on Service1, and making the engine which will be integrated into the app that customer support uses to play around with the users and data of that service on customer requests, I'd like to create that engine under CompanyName::Serive1::CustomerSupport

However rails seems to be unable to do that.

What I'd like to achieve is an engine whose controllers, models and views are generated under the a::b::blah namespace, and it is mountable the same way. I want all generated controllers to go under app/controllers/a/b/blah, the models to go under app/models/a/b/blah, and so on...

Is there a way to achieve this?


Solution

  • For anyone reading this in 2022, I believe later versions of Rails handle engine names with dashes as separate namespaces.

    rails plugin new parent_engine-sub_engine --mountable

    Will create the following engine.rb:

    module ParentEngine
      module SubEngine
        class Engine < ::Rails::Engine
          isolate_namespace ParentEngine::SubEngine
        end
      end
    end