0
0
Ruby on Railsframework~10 mins

Route parameters 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 a route that captures an :id parameter.

Ruby on Rails
get '/products/[1]', to: 'products#show'
Drag options to blanks, or click blank then click option'
A*id
Bid
C:id
D?id
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the colon before the parameter name.
Using a question mark or asterisk instead of a colon.
2fill in blank
medium

Complete the code to access the route parameter :id inside the controller action.

Ruby on Rails
def show
  @product = Product.find(params[[1]])
end
Drag options to blanks, or click blank then click option'
A:id
B'id'
Cid
D:'id'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the key (syntax error with bare id).
Using ":id" (accesses nonexistent params[":id"]).
3fill in blank
hard

Fix the error in the route to correctly capture a username parameter.

Ruby on Rails
get '/users/[1]', to: 'users#profile'
Drag options to blanks, or click blank then click option'
A:username
Busername
C*username
D?username
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the colon before the parameter name.
Using wildcard or query syntax instead of colon.
4fill in blank
hard

Fill both blanks to define a nested route with :post_id and :comment_id parameters.

Ruby on Rails
get '/posts/[1]/comments/[2]', to: 'comments#show'
Drag options to blanks, or click blank then click option'
A:post_id
Bpost_id
C:comment_id
Dcomment_id
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out colons before parameter names.
Using parameter names without colon prefixes.
5fill in blank
hard

Fill all three blanks to define a route with :category, :id, and :format parameters.

Ruby on Rails
get '/[1]/[2].[3]', to: 'items#show'
Drag options to blanks, or click blank then click option'
A:category
B:id
C:format
Dformat
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting colons before parameter names.
Not including the dot before the format parameter.