0
0
Ruby on Railsframework~5 mins

Root route in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aapp/controllers/application_controller.rb
Bconfig/routes.rb
Cconfig/database.yml
Dapp/views/layouts/application.html.erb
What does this line do? root 'welcome#home'
ARedirects all routes to welcome#home
BCreates a new controller named welcome
CSets the homepage to the home action in welcome controller
DDeletes the welcome controller
What happens if you visit the base URL without a root route defined?
AYou get an error page
BRails shows a default homepage
CRails redirects to /index
DRails shows a blank page
Can the root route point to a non-existent action?
ANo, it must point to a view file
BYes, Rails creates the action automatically
CYes, but it shows a blank page
DNo, it must point to an existing action
Which of these is a valid root route declaration?
Aroot 'pages#about'
Broot to: 'pages#about'
Croot pages#about
Droot: 'pages#about'
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.