Challenge - 5 Problems
Routing Mastery in Rails
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
What does routing do in Rails?
In Rails, what is the main purpose of routing?
Attempts:
2 left
💡 Hint
Think about how a web address leads to a page or action.
✗ Incorrect
Routing in Rails links a URL to a controller action, which decides what to do next.
❓ component_behavior
intermediate1:30remaining
What happens when you visit '/posts/5'?
Given this route in Rails:
get '/posts/:id', to: 'posts#show', what action is triggered when visiting '/posts/5'?Ruby on Rails
get '/posts/:id', to: 'posts#show'
Attempts:
2 left
💡 Hint
Look at the route pattern and the controller#action format.
✗ Incorrect
The route matches '/posts/:id' and sends the request to the 'show' action with the id parameter.
📝 Syntax
advanced2:00remaining
Identify the correct route syntax for a 'create' action
Which of the following route definitions correctly maps a POST request to the 'create' action in the 'articles' controller?
Attempts:
2 left
💡 Hint
Remember which HTTP verb is used to create new resources.
✗ Incorrect
POST requests are used to create new resources, so the route must use 'post'.
🔧 Debug
advanced2:00remaining
Why does this route cause an error?
Given the route:
get '/users/:id/edit', to: 'users#edit', why does visiting '/users/edit' cause an error?Ruby on Rails
get '/users/:id/edit', to: 'users#edit'
Attempts:
2 left
💡 Hint
Look carefully at the URL pattern and what parts are required.
✗ Incorrect
The route expects an :id between '/users/' and '/edit', so '/users/edit' misses the id.
❓ state_output
expert2:00remaining
What is the output of this routing helper?
Given the route
resources :products, what is the output of product_path(10) in a Rails view?Ruby on Rails
resources :products
Attempts:
2 left
💡 Hint
Think about the URL pattern for showing a single resource.
✗ Incorrect
The helper product_path(10) generates the URL to show the product with id 10, which is '/products/10'.