Skip to main content

isolate_namespace_advanced

⚙️ Leverage Advanced isolate_namespace Customizations

By default, isolate_namespace sets up a module scope, but you can extend it to customize route names, controller paths, and view prefixes for absolute isolation. This ensures no constant collisions or route helper clashes with the host application. Use initializers in your engine.rb to override defaults and inject your own naming convention.

# lib/my_engine/engine.rb
engine_name = :my_engine
module MyEngine
class Engine < ::Rails::Engine
isolate_namespace MyEngine

initializer "#{engine_name}.route_helpers" do |app|
app.routes.named_routes.helper_names[:main_app_path] = "#{engine_name}_main_app"
end

initializer "#{engine_name}.view_prefixes" do |_|
ActiveSupport.on_load(:action_controller) do
prepend_view_path MyEngine::Engine.root.join('app', 'views', 'shared_#{engine_name}')
end
end
end
end