Challenge - 5 Problems
Master of Member and Collection Routes
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of member route URL helper
Given the following routes in a Rails application:
What is the output of
resources :books do
member do
get 'preview'
end
endWhat is the output of
preview_book_path(5)?Attempts:
2 left
💡 Hint
Member routes add actions for a single resource identified by ID.
✗ Incorrect
Member routes add a custom action for a single resource, so the URL includes the resource ID before the action name.
❓ query_result
intermediate2:00remaining
Output of collection route URL helper
Given the following routes in a Rails application:
What is the output of
resources :orders do
collection do
get 'recent'
end
endWhat is the output of
recent_orders_path?Attempts:
2 left
💡 Hint
Collection routes add actions that apply to the whole collection, no ID needed.
✗ Incorrect
Collection routes add a custom action for the entire resource collection, so the URL does not include an ID.
📝 Syntax
advanced2:00remaining
Identify the invalid member route syntax
Which option contains invalid syntax for defining a member route inside
resources :products?Attempts:
2 left
💡 Hint
Member routes require a block with do...end or braces.
✗ Incorrect
Option B is invalid because it tries to call member without a block, which is not valid syntax in Rails routing DSL.
🧠 Conceptual
advanced2:00remaining
Difference between member and collection routes
Which statement correctly describes the difference between member and collection routes in Rails?
Attempts:
2 left
💡 Hint
Think about whether the route URL includes an ID or not.
✗ Incorrect
Member routes are for actions on a single resource and include the ID in the URL. Collection routes are for actions on the whole collection and do not include an ID.
🔧 Debug
expert3:00remaining
Why does this member route cause a routing error?
Consider this routes definition:
Why will calling
resources :users do
member do
get 'profile/:section'
end
endWhy will calling
profile_user_path(3, section: 'settings') cause a routing error?Attempts:
2 left
💡 Hint
Member routes define actions for a single resource; dynamic segments inside member blocks are not supported this way.
✗ Incorrect
Rails member routes do not support adding extra dynamic segments in the path inside the member block. This causes routing errors.