0
0
Ruby on Railsframework~10 mins

RESTful resource routes in Ruby on Rails - Interactive Code Practice

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

Complete the code to define RESTful routes for a resource named 'articles'.

Ruby on Rails
Rails.application.routes.draw do
  resources :[1]
end
Drag options to blanks, or click blank then click option'
Aarticle
Barticles
Cposts
Darticle_list
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular form instead of plural.
Using unrelated resource names.
2fill in blank
medium

Complete the code to add only the 'index' and 'show' actions to the resource routes.

Ruby on Rails
Rails.application.routes.draw do
  resources :products, only: [:[1]]
end
Drag options to blanks, or click blank then click option'
Aindex, show
Bcreate, update
Cindex
Dnew, edit
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an array.
Including actions not intended.
3fill in blank
hard

Fix the error in the code to correctly nest comments inside posts.

Ruby on Rails
Rails.application.routes.draw do
  resources :posts do
    resources :[1]
  end
end
Drag options to blanks, or click blank then click option'
Acomment_list
Bcomment
Cpost_comments
Dcomments
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular form for nested resources.
Using incorrect resource names.
4fill in blank
hard

Fill both blanks to define a custom member route named 'preview' for articles.

Ruby on Rails
Rails.application.routes.draw do
  resources :articles do
    [1] :preview, on: :[2]
  end
end
Drag options to blanks, or click blank then click option'
Amember
Bcollection
Cpost
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing member and collection routes.
Using wrong HTTP verbs.
5fill in blank
hard

Fill all three blanks to define nested routes for posts and comments with only 'create' and 'destroy' actions for comments.

Ruby on Rails
Rails.application.routes.draw do
  resources :posts do
    resources :comments, only: [:[1], :[2]], [3]: true
  end
end
Drag options to blanks, or click blank then click option'
Acreate
Bdestroy
Cshallow
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Including unwanted actions in 'only'.
Forgetting to add 'shallow: true' for better route structure.