Complete the code to define a route that captures an :id parameter.
get '/products/[1]', to: 'products#show'
The route parameter must be prefixed with a colon : to capture it as a variable.
Complete the code to access the route parameter :id inside the controller action.
def show @product = Product.find(params[[1]]) end
id).":id" (accesses nonexistent params[":id"]).In Rails controllers, route parameters are conventionally accessed using strings as keys in the params hash, like params['id']. The option 'id' is the correct string key.
Fix the error in the route to correctly capture a username parameter.
get '/users/[1]', to: 'users#profile'
The route parameter must have a colon prefix to be recognized as a parameter.
Fill both blanks to define a nested route with :post_id and :comment_id parameters.
get '/posts/[1]/comments/[2]', to: 'comments#show'
Both parameters must have a colon prefix to be recognized as route parameters.
Fill all three blanks to define a route with :category, :id, and :format parameters.
get '/[1]/[2].[3]', to: 'items#show'
All route parameters must have a colon prefix to be recognized by Rails routing.