Recall & Review
beginner
What are route parameters in Rails?
Route parameters are dynamic parts of a URL that Rails captures and passes to controller actions as variables. They let you handle URLs with changing values, like user IDs.Click to reveal answer
beginner
How do you define a route with a parameter in Rails?
You add a colon before a name in the route path, like
get '/users/:id', to: 'users#show'. The :id is the route parameter.Click to reveal answer
beginner
How do you access route parameters inside a Rails controller?
You use the
params hash. For example, params[:id] gives you the value of the :id parameter from the URL.Click to reveal answer
intermediate
What happens if a route parameter is missing in the URL?
If the route expects a parameter but it is missing, Rails will not match that route and usually returns a 404 error because the URL does not fit the route pattern.
Click to reveal answer
intermediate
Can route parameters be used for multiple values in Rails?
Yes, you can define multiple parameters like
/posts/:post_id/comments/:id. Each parameter is accessible via params[:post_id] and params[:id].Click to reveal answer
In Rails, how do you define a route that accepts a user ID as a parameter?
✗ Incorrect
The colon before 'id' defines a route parameter named 'id'.
How do you access the route parameter 'id' inside a Rails controller?
✗ Incorrect
Route parameters are accessed via the params hash using symbols, like params[:id].
What will happen if you visit '/users/' but the route expects '/users/:id'?
✗ Incorrect
The route requires an :id parameter, so missing it causes no match and a 404 error.
Can you have multiple route parameters in a single Rails route?
✗ Incorrect
Rails supports multiple parameters in routes by adding multiple colon-prefixed names.
Which of these is NOT a valid route parameter name in Rails?
✗ Incorrect
Parameter names must start with a letter or underscore, not a number.
Explain how route parameters work in Rails and how you use them in a controller.
Think about how URLs can change and how Rails captures those changes.
You got /4 concepts.
Describe what happens when a route parameter is missing in a URL that expects it.
Consider how Rails matches URLs to routes.
You got /3 concepts.