Layout namespacing
This course follows how a Rails app decides which layout wraps each page. Public pages render inside application.html.erb, and every page under /admin renders inside admin.html.erb. The switch is one line, layout "admin", in Admin::BaseController. The lessons read the installed ActionView::Layouts source to show how nested Admin:: controllers inherit that value through class_attribute. They also show how controllers with no layout call fall back to application.html.erb by convention. Finally, they compare both layout files line by line and cover the Symbol, Proc and render layout: false forms.
What you'll learn
- ✓What the layout class method does and where it is declared
- ✓How class_attribute passes a layout down to nested Admin:: controllers
- ✓How Rails finds application.html.erb when no layout is declared
- ✓The differences and shared partials between the public and admin layouts
- ✓Symbol and Proc layouts, and render layout: false for a single action
Two layouts, one line that switches between them
app/views/layouts/application.html.erb and app/views/layouts/admin.html.erb. Every public page, such as the roadmap, a course or a lesson, is wrapped in the first. Every page under /admin, such as the dashboard or the course editor, is wrapped in the second: a sidebar-driven layout with no navbar…
Read the full lesson free →Curriculum
7 lessonsTwo layouts, one line that switches between them
Introduces the public and admin layout files and the single layout "admin" line that separates them.
The layout class method, declared once in Admin::BaseController
Explains layout as a class method from ActionView::Layouts that records configuration and renders nothing by itself.
Inheritance: why a controller nested under Admin:: needs no redeclaration
Shows how class_attribute lets Admin::Catalog::CoursesController inherit the admin layout without any layout call of its own.
The default when nothing is declared: how application.html.erb is found
Traces the convention lookup through controller_path that leads public controllers to layouts/application.html.erb.
Reading both layouts side by side
Compares navigation, head tags, stylesheets and modals in both layouts, plus the partials they share.
layout as a Symbol or a Proc: documented, and unused in this app's controllers
Covers the Symbol and Proc forms, unused here, and the per-action render layout: false in CommentsController.
Putting it together: one declaration, inherited where it applies
Reviews the full layout resolution model and closes with a pure Ruby challenge simulating it.