0
0
Ruby on Railsframework~20 mins

Why routing maps URLs to actions in Ruby on Rails - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Routing Mastery in Rails
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What does routing do in Rails?
In Rails, what is the main purpose of routing?
AIt connects URLs to specific controller actions that handle requests.
BIt stores user data in the database automatically.
CIt styles the HTML pages with CSS.
DIt compiles Ruby code into machine code.
Attempts:
2 left
💡 Hint
Think about how a web address leads to a page or action.
component_behavior
intermediate
1: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'
AThe application returns a 404 error because the route is invalid.
BThe 'show' action in the PostsController is called with id = 5.
CThe 'edit' action in the PostsController is called with id = 5.
DThe 'index' action in the PostsController is called.
Attempts:
2 left
💡 Hint
Look at the route pattern and the controller#action format.
📝 Syntax
advanced
2: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?
Apost '/articles', to: 'articles#create'
Bget '/articles/create', to: 'articles#create'
Cput '/articles', to: 'articles#create'
Ddelete '/articles', to: 'articles#create'
Attempts:
2 left
💡 Hint
Remember which HTTP verb is used to create new resources.
🔧 Debug
advanced
2: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'
ABecause the 'edit' action does not exist in UsersController.
BBecause the HTTP verb should be POST, not GET.
CBecause '/users/edit' does not match the pattern requiring an :id before '/edit'.
DBecause the route should be defined with 'resources :users' instead.
Attempts:
2 left
💡 Hint
Look carefully at the URL pattern and what parts are required.
state_output
expert
2: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
A"/products/10/edit"
B"/products/show/10"
C"/products?id=10"
D"/products/10"
Attempts:
2 left
💡 Hint
Think about the URL pattern for showing a single resource.