Skip to main content

engine_isolated_layouts

🚀 Engine-Isolated Layouts​

When building Rails Engines, isolate layouts inside the engine to prevent collisions and allow host apps to override. Use isolate_namespace and set layout within the engine's base controller.

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

class ApplicationController < ActionController::Base
layout 'blog_engine/application'
end
end

Place your engine layouts in app/views/layouts/blog_engine/application.html.erb. The host app can override by creating a same-named file in its app/views/layouts/blog_engine directory, promoting clear boundaries.