0
0
Ruby on Railsframework~20 mins

Member and collection routes in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
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
intermediate
2:00remaining
Output of member route URL helper
Given the following routes in a Rails application:
resources :books do
  member do
    get 'preview'
  end
end

What is the output of preview_book_path(5)?
A/books/5/preview
B/books/preview/5
C/preview/books/5
D/books/5/preview_book
Attempts:
2 left
💡 Hint
Member routes add actions for a single resource identified by ID.
query_result
intermediate
2:00remaining
Output of collection route URL helper
Given the following routes in a Rails application:
resources :orders do
  collection do
    get 'recent'
  end
end

What is the output of recent_orders_path?
A/recent/orders
B/orders/:id/recent
C/orders/recent_orders
D/orders/recent
Attempts:
2 left
💡 Hint
Collection routes add actions that apply to the whole collection, no ID needed.
📝 Syntax
advanced
2:00remaining
Identify the invalid member route syntax
Which option contains invalid syntax for defining a member route inside resources :products?
A
member do
  delete 'remove'
end
Bmember get 'details'
C
member do
  post 'purchase'
end
D
member do
  get 'details'
end
Attempts:
2 left
💡 Hint
Member routes require a block with do...end or braces.
🧠 Conceptual
advanced
2:00remaining
Difference between member and collection routes
Which statement correctly describes the difference between member and collection routes in Rails?
ABoth member and collection routes always include the resource ID in the URL.
BMember routes apply to the entire collection; collection routes apply to a single resource with an ID.
CMember routes apply to a single resource and include the resource ID in the URL; collection routes apply to the entire collection without an ID.
DMember routes are only for POST requests; collection routes are only for GET requests.
Attempts:
2 left
💡 Hint
Think about whether the route URL includes an ID or not.
🔧 Debug
expert
3:00remaining
Why does this member route cause a routing error?
Consider this routes definition:
resources :users do
  member do
    get 'profile/:section'
  end
end

Why will calling profile_user_path(3, section: 'settings') cause a routing error?
AMember routes cannot have dynamic segments like ':section' inside the block.
BThe dynamic segment ':section' must be declared outside the member block.
CThe route helper expects two arguments, but only one is given.
DThe route helper method name is incorrect; it should be 'profile_section_user_path'.
Attempts:
2 left
💡 Hint
Member routes define actions for a single resource; dynamic segments inside member blocks are not supported this way.