Recall & Review
beginner
What are nested routes in Rails?
Nested routes are routes defined inside other routes to show a parent-child relationship between resources, like comments belonging to posts.
Click to reveal answer
beginner
How do you define a nested route in Rails?
You use the
resources method inside another resources block in config/routes.rb. For example:<br>resources :posts do resources :comments end
Click to reveal answer
beginner
What URL pattern does a nested route generate for comments inside posts?
It generates URLs like
/posts/:post_id/comments/:id, showing the comment belongs to a specific post.Click to reveal answer
intermediate
Why use nested routes in a Rails app?
Nested routes help organize URLs to reflect relationships between resources, making the app easier to understand and the URLs more meaningful.
Click to reveal answer
intermediate
What is a potential downside of deeply nested routes?
Deeply nested routes can create very long and complex URLs and make controllers harder to manage. Rails recommends keeping nesting to 1 or 2 levels.
Click to reveal answer
Which of the following is the correct way to nest comments inside posts in Rails routes?
✗ Incorrect
Option B correctly nests comments inside posts using the resources block.
What URL would Rails generate for editing a comment with id 5 on post with id 2 using nested routes?
✗ Incorrect
Nested routes include the parent resource id first, so the URL is /posts/2/comments/5/edit.
What is a recommended maximum nesting depth for routes in Rails?
✗ Incorrect
Rails recommends keeping nesting to 1 or 2 levels to avoid complexity.
Which method is used to define routes in Rails?
✗ Incorrect
The resources method is used to define RESTful routes in Rails.
What does the nested route
resources :posts do resources :comments end imply about the relationship?✗ Incorrect
Nesting comments inside posts means comments belong to posts.
Explain how nested routes work in Rails and why they are useful.
Think about how comments belong to posts and how URLs show that.
You got /4 concepts.
Describe the potential problems with deeply nested routes and how to avoid them.
Less is more with nesting levels.
You got /3 concepts.