0
0
Ruby on Railsframework~10 mins

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

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a route that maps the URL '/home' to the 'index' action of the 'pages' controller.

Ruby on Rails
get '/home', to: '[1]'
Drag options to blanks, or click blank then click option'
Apages#index
Bpages#show
Chome#show
Dhome#index
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong controller name.
Using the wrong action name.
Forgetting the '#' between controller and action.
2fill in blank
medium

Complete the code to create a route that maps a GET request for '/products/:id' to the 'show' action in the 'products' controller.

Ruby on Rails
get '/products/:id', to: '[1]'
Drag options to blanks, or click blank then click option'
Aproducts#edit
Bproducts#index
Cproducts#show
Ditems#show
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'index' instead of 'show' for a single item.
Using the wrong controller name.
Missing the '#' between controller and action.
3fill in blank
hard

Fix the error in the route that should map POST requests to '/users' to the 'create' action in the 'users' controller.

Ruby on Rails
post '/users', to: '[1]'
Drag options to blanks, or click blank then click option'
Ausers#new
Busers#create
Cusers#update
Duser#create
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' instead of 'create' for POST requests.
Using singular controller name 'user' instead of 'users'.
Using 'update' which is for PATCH/PUT requests.
4fill in blank
hard

Fill both blanks to define a route that maps DELETE requests for '/articles/:id' to the 'destroy' action in the 'articles' controller.

Ruby on Rails
[1] '/articles/:id', to: '[2]'
Drag options to blanks, or click blank then click option'
Adelete
Bdestroy
Cremove
Darticles#destroy
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove' which is not a valid HTTP verb.
Using 'destroy' as the HTTP verb instead of the action.
Mixing up the controller and action in the route string.
5fill in blank
hard

Fill all three blanks to define a route that maps PATCH requests for '/profiles/:id' to the 'update' action in the 'profiles' controller with a named route helper 'profile_update'.

Ruby on Rails
[1] '/profiles/:id', to: '[2]', as: '[3]'
Drag options to blanks, or click blank then click option'
Apatch
Bprofiles#update
Cprofile_update
Dput
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'put' instead of 'patch' for partial updates.
Using the wrong controller or action name.
Forgetting to add the named route helper.