Challenge 3: Versioned Routes — Solution # config/routes.rb namespace :api do namespace :v1 do resources :comments end end # generates: /api/v1/comments, /api/v1/comments/:id, ... # app/controllers/api/v1/comments_controller.rb module Api module V1 class CommentsController < ApplicationController # ... end end end =begin Notes: - Each namespace call adds one segment to both the URL path and the expected module nesting for the controller -- namespace :api then namespace :v1 together produce the /api/v1/... path prefix and require the controller to live at Api::V1::CommentsController, matching Rails' path-mirrors-module-structure convention. - resources :comments inside the nested namespace still generates all 7 RESTful routes from rails1-2, just under the versioned prefix -- nothing about the route-generation behavior itself changes. - The module Api / module V1 nesting in the controller file is required to match the namespace declaration exactly; a class defined as plain CommentsController in that file would not be found by the versioned route. - Adding a v2 namespace later (Api::V2::CommentsController) can coexist with this file untouched, letting existing API consumers keep using v1 while v2 is developed. =end