📕 5 How to add a page
⬅️ index
📺 Link to original video by Go Rails.

⚠️ This is how to add a page without any interaction with the model.

Create a route 🛤️ 

  1. Go to config > routes.rb file
  1. In the Rails.application.routes.draw method, enter a route using the syntax:
  • [request type] "[URL]", to: "[controller]#[action]"

Create a controller 👨‍✈️ 

  1. Go to app > controllers folder
  1. Create a file named [route]_controller.rb, e.g. about_controller.rb
  1. Create a class named [Route]Controller and inherit from ApplicationController
  1. Define a method named [action from routes.rb], e.g. index

Create a view 🏞️ 

  1. Go to app > views folder
  1. Create a folder named [route]
  1. In that folder create a file named [action.html.erb]
  1. Add HTML (and ERB)

View new page 👀 

  1. You’ll see the new page
  1. Open Web Inspector
  • 👀 You’ll see the request from the browser and the response from the server for the GET request to the /about URL.
  1. View the page’s source code
  • 👀 You’ll see the content that Rails added code from app > views > layouts > application.html.erb and inserted the code from index.html.erb inside the <%= yield => ERB tag.
⬅️ index