0
0
Ruby on Railsframework~5 mins

Member and collection routes in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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>end
Click 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>end
Click 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?
ANamespace route
BCollection route
CMember route
DRoot route
How do you define a collection route inside a resource block?
AUsing <code>collection do</code>
BUsing <code>resource do</code>
CUsing <code>member do</code>
DUsing <code>namespace do</code>
What URL would a member route named 'preview' generate for a book with ID 5?
A/books/5/preview
B/books/preview
C/preview/books/5
D/books/5
Which HTTP verb is commonly used for a collection route that lists filtered results?
ADELETE
BGET
CPOST
DPUT
If you want to add a custom action that applies to all books, which route type should you use?
ARoot route
BMember route
CSingular resource route
DCollection route
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.