2 min read

Hello World Rails Speed Run

The goal of this post is to create a Hello World Rails application. By the end, we'll run this application locally.
Hello World Rails Speed Run

Goal

The goal of this post is to create a Hello World Rails application. By the end, we'll run this application locally.

Steps

You first need to have Ruby on Rails 8 installed. If you are not sure how, see the getting started guide.

❯ rails --version
Rails 8.0.1

There is nothing quite as magical as typing rails new into terminal. It's a moment of possibility and hope. There are few actions quite as optimistic in today's world.

Create a new Rails application. I'll call mine kamal_demo and I'll use tailwind.css for style.

rails new kamal_demo --css=tailwind

After the new Rails application generates, change directories into the project.

cd kamal_demo

Open an editor that sparks joy. I'll be using Windsurf, because I live in the future.

windsurf .

Now let's create a page that we will be able to access on the VM we created in Baby's First Google Compute Instance.

Open config/routes.rb

We'll define a new route for when we visit our root /.

# config/routes.rb
Rails.application.routes.draw do
  get "up" => "rails/health#show", as: :rails_health_check

  # Defines the root path route ("/")
  root "pages#home"
end

Next let's create a controller and view. Run rails g controller Pages home.

❯ rails g controller Pages home
      create  app/controllers/pages_controller.rb
       route  get "pages/home"
      invoke  tailwindcss
      create    app/views/pages
      create    app/views/pages/home.html.erb
      invoke  test_unit
      create    test/controllers/pages_controller_test.rb
      invoke  helper
      create    app/helpers/pages_helper.rb
      invoke    test_unit

Open the new app/views/pages/home.html.erb. Add something dynamic, like the current time and also something self-affirming because this is hard and you are great.

<div>
  <h1 class="font-bold text-4xl">You are awesome.</h1>
  <p>Current time: <%= Time.now.strftime("%B %d, %Y at %I:%M %p") %></p>
</div>

Run bin/dev to start our local server.

Next in your browser navigate to localhost:3000 and you will see the contents of home.html.erb.

Bask in your self affirmation.

Conclusion

We now have a basic hello world Rails application running locally. Now it is time get our Kamal configuration ready to deploy it to our VM from Baby's First Google Compute Instance.

To start, we'll need to setup a repository for our Docker images. Artifact Registry Setup will explain more.

Source documentation

Next post

Artifact Registry Setup

Previous post

Bootstrap the Virtual Machine