Recall & Review
beginner
What is the purpose of the root route in a Rails application?
The root route defines the default page users see when they visit the base URL of the app, like visiting www.example.com without any extra path.
Click to reveal answer
beginner
How do you set the root route in Rails?
You set it in the config/routes.rb file using
root 'controller#action'. For example, root 'home#index' makes the home controller's index action the homepage.Click to reveal answer
beginner
What happens if you don't define a root route in a Rails app?
Visiting the base URL will cause an error because Rails won't know which page to show by default.
Click to reveal answer
beginner
Can the root route point to any controller and action?
Yes, the root route can point to any controller and action you want to be the homepage, as long as that action exists and can render a view.
Click to reveal answer
beginner
Example: What does this line do?
root 'dashboard#main'It sets the root URL to show the
main action inside the dashboard controller. So visiting the base URL loads that page.Click to reveal answer
Where do you define the root route in a Rails app?
✗ Incorrect
The root route is set in the config/routes.rb file.
What does this line do?
root 'welcome#home'✗ Incorrect
It sets the root URL to show the home action inside the welcome controller.
What happens if you visit the base URL without a root route defined?
✗ Incorrect
Without a root route, Rails does not know which page to show and returns an error.
Can the root route point to a non-existent action?
✗ Incorrect
The root route must point to an existing controller action to work properly.
Which of these is a valid root route declaration?
✗ Incorrect
The correct syntax is root 'controller#action'.
Explain how to set a root route in a Rails app and why it is important.
Think about the file where routes live and what the root route controls.
You got /5 concepts.
Describe what happens if a Rails app does not have a root route defined and a user visits the base URL.
Consider what Rails needs to know to show a page at the main URL.
You got /4 concepts.