method

isolate_namespace

v3.1.0 - Show latest stable - Class: Rails::Engine
isolate_namespace(mod)
public

No documentation available.

# File railties/lib/rails/engine.rb, line 359
      def isolate_namespace(mod)
        engine_name(generate_railtie_name(mod))

        self.routes.default_scope = { :module => ActiveSupport::Inflector.underscore(mod.name) }
        self.isolated = true

        unless mod.respond_to?(:_railtie)
          name = engine_name
          _railtie = self
          mod.singleton_class.instance_eval do
            define_method(:_railtie) do
              _railtie
            end

            unless mod.respond_to?(:table_name_prefix)
              define_method(:table_name_prefix) do
                "#{name}_"
              end
            end
         end
        end
      end

2Notes

Some documentation available in RailsGuides

hehaveri · Jan 18, 2013

The Rails engines getting started guide discusses the usage of isolate_namespace: http://edgeguides.rubyonrails.org/engines.html

isolate_namespace description with example

taimoorchangaiz · Jul 16, 2013

Normally when you create controllers, helpers and models inside an engine, they are treated as if they were created inside the application itself. This means that all helpers and named routes from the application will be available to your engine’s controllers as well.

However, sometimes you want to isolate your engine from the application, especially if your engine has its own router. To do that, you simply need to call isolate_namespace. This method requires you to pass a module where all your controllers, helpers and models should be nested to:

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

With such an engine, everything that is inside the MyEngine module will be isolated from the application.

Detail reference: http://edgeapi.rubyonrails.org/classes/Rails/Engine.html