Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Understanding Routing.docx58.7 KB Understanding Routing - Solution.docx
58.6 KB
Quick reference
Understanding Routing
In this video we'll be discussing the basics of Routing in Rails.
When to use
Any time you create a web page, you need to set up a route to that web page (either automatically using the Rails Generator, or manually).
Instructions
When using the Rails Generator, your route will be created automatically in the /config/routes.rb file. For our first index web page, that route will look like this:
get 'home/index'
To change the route of that page to make it our root homepage, change the above line of code to this:
root 'home#index'
That creates a "Root Route".
Remember that you can check your routes in the terminal at any time by using the "Rake Routes" command.
Hints & tips
- Every webpage needs a route
- Routes are found in the /config/routes.rb file
- A basic route looks like this: get 'home/index'
- A root route looks like this: root 'home#index'
- To view your current routes use this command in the terminal: rake routes
Lesson notes are only available for subscribers.