Creating Boring Static Pages

I hope to demonstrate at a very basic level, the concept of controller being used to generate view in Rails. Eventually, I will create a skeleton of a modern web 2.0 landing page.

1. Update Gemfile

source 'http://rubygems.org'
gem 'rails', '3.0.10'
gem 'sqlite3'
end

2. On your console, in the Rails directory

>> Bundle Install

3. Create pages_controller.rb and update

class PagesController < ApplicationController
  def home
  end

  def contact
  end

  def team
  end
end

4. Create the following files in this directory, /app/views/pages/...html.erb

  • home.html.erb
  • contact.html.erb
  • team.html.erb

5. Content for the three html.erb can be anything. It doesn't matter for now.

6. Check http://localhost:3000/pages/home

You will see this routing error.

No route matches "/pages/home"

7. Don't worry. Open /config/routes.rb and update

LandingPage::Application.routes.draw do
  get "pages/home"
  get "pages/contact"
  get "pages/team"
end

The error should be gone if you refresh http://localhost:3000/pages/home

get "pages/home" is equivalent to get "pages/home" => "pages#home"

"controller_name/method" => "the way it looks in browser url. # denotes / in the url."