About this lesson
Let's build our first Rails Web Page!
Download this lesson’s related exercise files.Creating Our First Web Page.docx
199.5 KB Creating Our First Web Page - Solution.docx
Creating Our First Web Page
In this video we'll be creating our first web page with Rails.
When to use
Rails gives you two main ways to create web pages in your app; manually or automatically using the Rails Generator.
To create a web page with the Rails Generator, use this command in the terminal:
rails generate controller home index
Remember, all pages need a controller, an HTML file, and a route. The command above gives us a controller named home and a web page named index and creates a route for us automatically.
Hints & tips
- Rails gives us two ways to create web pages; manually or automatically using the Rails Generator
- Rails generate controller home index is the terminal command to create a web page automatically
- All web pages require a controller, an HTML file, and a route
- Routes are located in the /config/routes.rb file
- Controllers are located in the app/controllers/ directory
- Webpage HTML files are located in the app/views/home/ directory
- When using the generate command, a shortcut is to type g instead of generate
- .erb stands for embedded Ruby and allows us to use Ruby code on our web pages
Lesson notes are only available for subscribers.