Nested resources biểu diễn quan hệ cha-con trong URL: /posts/:post_id/comments — comment luôn thuộc về 1 post cụ thể.
ruby
# config/routes.rb
resources :posts do
resources :comments, only: [:index, :create, :destroy]
endRoute được tạo: GET /posts/:post_id/comments, POST /posts/:post_id/comments, ...
Trong CommentsController, lấy post qua Post.find(params[:post_id]) rồi build comment từ @post.comments.
Best practice: chỉ nest 1 cấp — /posts/:post_id/comments OK, nhưng nest sâu hơn khó đọc và khó maintain.