Junior Track Roadmap

Nested resource routing

This course covers nested resource routing in Rails, using the admin routes, controllers and Rails source of one app. It explains how nesting resources :lessons inside resources :courses adds :course_id to the URL. It covers shallow: true and which actions it flattens, singular resource routes with no :id and plural controller names, and member blocks for a custom reorder action. It also covers module: and scope module: for controller subdirectories, and why shallow flattens nested plural resources but leaves singular ones nested.

What you'll learn

  • ✓How nesting one resource inside another adds the parent id to the URL and params
  • ✓Which actions shallow: true keeps nested and which it flattens to a bare :id
  • ✓How singular resource routes drop :id and still map to a plural-named controller
  • ✓Adding custom actions with member blocks, and how collection blocks differ
  • ✓Using module: and scope module: to place controllers in subdirectories
  • ✓Why shallow flattens nested plural resources but not singular ones
Free preview · Lesson 1 3 min read

Nesting a resource: putting a "belongs to" relationship into the URL

Rails routes: basics, earlier in this series, showed resources :courses, param: :slug, only: [ :show ], this app's routing for public course pages. Every resources call in that course is a single, standalone resource; none of its seven lessons puts one resources block inside another. That course…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...