Recall & Review
beginner
What is a named route in Rails?
A named route is a shortcut that Rails creates for a URL pattern. It lets you use a simple method name instead of writing the full URL or path every time.
Click to reveal answer
beginner
How do you use a path helper in a Rails view?
You call the helper method like
posts_path or new_post_path to get the URL or path string for that route. This helps keep your code clean and easy to change.Click to reveal answer
intermediate
Example: What does
edit_user_path(@user) return?It returns the URL path to edit the user with the ID of
@user. For example, if @user.id is 5, it returns /users/5/edit.Click to reveal answer
beginner
Why are named routes and path helpers better than hardcoding URLs?
They make your code easier to read and maintain. If you change the route in one place, all helpers update automatically. It also helps avoid mistakes and broken links.
Click to reveal answer
intermediate
How do you define a named route in Rails routes file?
You define it by giving a name to a route in
config/routes.rb. For example, get 'profile', to: 'users#show', as: 'profile' creates a profile_path helper.Click to reveal answer
What does the helper
new_post_path usually return?✗ Incorrect
new_post_path returns the path to the form where you can create a new post, usually /posts/new.
How do you pass a model instance to a path helper for a show page?
✗ Incorrect
Passing the model instance lets Rails extract the ID and build the correct path, like /posts/3.
What is the benefit of using named routes over hardcoded URLs?
✗ Incorrect
Named routes keep your code DRY and update automatically if you change routes.
Where do you define named routes in a Rails app?
✗ Incorrect
All routes, including named routes, are defined in config/routes.rb.
What helper method would Rails create for this route?
get 'dashboard', to: 'home#index', as: 'dashboard'✗ Incorrect
The as: 'dashboard' option creates the dashboard_path helper.
Explain what named routes and path helpers are in Rails and why they are useful.
Think about how you avoid repeating full URLs in your code.
You got /4 concepts.
Describe how you would use a path helper in a Rails view to link to a user's edit page.
Consider how you create links to edit forms in Rails.
You got /4 concepts.