Recall & Review
beginner
What is a member route in Rails routing?
A member route is a custom route that acts on a single resource identified by its ID. It adds a route that requires the resource's ID in the URL.
Click to reveal answer
beginner
What is a collection route in Rails routing?
A collection route is a custom route that acts on the entire collection of resources, without needing an ID in the URL.
Click to reveal answer
intermediate
How do you define a member route in Rails routes.rb file?
Inside a resource block, use
member do and then define the HTTP verb and action, for example:<br>resources :books do<br> member do<br> get 'preview'<br> end<br>endClick to reveal answer
intermediate
How do you define a collection route in Rails routes.rb file?
Inside a resource block, use
collection do and then define the HTTP verb and action, for example:<br>resources :books do<br> collection do<br> get 'search'<br> end<br>endClick to reveal answer
beginner
What is the difference in URL structure between member and collection routes?
Member routes include the resource ID in the URL, like
/books/:id/preview. Collection routes do not include an ID, like /books/search.Click to reveal answer
Which route type requires the resource ID in the URL?
✗ Incorrect
Member routes act on a single resource and include the resource ID in the URL.
How do you define a collection route inside a resource block?
✗ Incorrect
Collection routes are defined inside
collection do blocks.What URL would a member route named 'preview' generate for a book with ID 5?
✗ Incorrect
Member routes include the resource ID, so the URL is /books/5/preview.
Which HTTP verb is commonly used for a collection route that lists filtered results?
✗ Incorrect
GET is used to retrieve filtered lists in collection routes.
If you want to add a custom action that applies to all books, which route type should you use?
✗ Incorrect
Collection routes apply to the entire set of resources.
Explain the difference between member and collection routes in Rails with examples.
Think about whether the route needs an ID or not.
You got /4 concepts.
How do you add a custom action to a resource in Rails routes.rb using member and collection blocks?
Remember the block names and URL patterns.
You got /4 concepts.