Challenge - 5 Problems
Rails Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this route helper?
Given the following route definition in
routes.rb, what URL will posts_path generate?Rails.application.routes.draw do resources :posts, only: [:index, :show] end
Attempts:
2 left
💡 Hint
The
posts_path helper corresponds to the index action URL for posts.✗ Incorrect
The resources :posts creates RESTful routes. The posts_path helper generates the URL for the index action, which is /posts.
📝 Syntax
intermediate2:00remaining
Which route definition correctly creates a nested resource?
You want to define routes so that comments belong to posts, accessible via URLs like
/posts/:post_id/comments. Which option correctly defines this in routes.rb?Attempts:
2 left
💡 Hint
Nested resources are defined by placing one
resources block inside another.✗ Incorrect
Option B correctly nests comments inside posts, creating URLs like /posts/:post_id/comments.
🔧 Debug
advanced2:00remaining
Why does this route cause a routing error?
Given this route definition:
And this URL request:
What error will Rails raise?
get 'profile/:id', to: 'users#show'
And this URL request:
/profileWhat error will Rails raise?
Attempts:
2 left
💡 Hint
The URL is missing a required parameter defined in the route.
✗ Incorrect
The route expects an :id parameter, but the URL /profile does not provide it. This causes a routing error because no matching route is found.
❓ state_output
advanced2:00remaining
What is the HTTP verb and path for this custom route?
Consider this route in
What HTTP verb and path does this route respond to?
routes.rb:post 'subscribe', to: 'newsletters#subscribe'
What HTTP verb and path does this route respond to?
Attempts:
2 left
💡 Hint
The first word in the route definition is the HTTP verb.
✗ Incorrect
The route responds to HTTP POST requests at the path /subscribe.
🧠 Conceptual
expert3:00remaining
How many routes are created by this line?
What is the total number of routes generated by this line in
routes.rb?resources :articles, only: [:index, :show, :create, :update, :destroy]
Attempts:
2 left
💡 Hint
Each action in the
only list creates one route.✗ Incorrect
The only option limits routes to the specified actions. Each action corresponds to one route, so 5 actions create 5 routes.