Creating a Rails Application with Tembo CLI
Prerequisites
Before you start, ensure you have the following installed:
- Ruby on Rails
- Tembo CLI. you can find the steps here
- Docker, set up and running for local development
Creating Your Rails Project
First, create a new Rails application with PostgreSQL as the database:
rails new todolist -d postgresql
cd todolist/
Initializing Tembo
Initialize Tembo in your project directory:
tembo init
Update your tembo.toml
file to match your project’s requirements. Example configuration:
[test-instance]
environment = "dev"
instance_name = "rails-todo"
cpu = "0.25"
memory = "1Gi"
storage = "10Gi"
replicas = 1
stack_type = "OLTP"
Set the Tembo context to local:
tembo context set --name local
Apply your Tembo configuration to provision the required infrastructure:
tembo apply
Configuring the Database
Update your config/database.yml
file with the Tembo PostgreSQL instance URL:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
url: postgres://postgres:postgres@rails-todo.local.tembo.io:5432
Create the database:
rails db:create
Creating a Todo Model
Generate a Todo model with a description field:
rails generate model Todo description:text
Migrate the database to create the todos table:
rails db:migrate
Verifying the Setup
Confirm the setup by connecting to the PostgreSQL instance and listing the databases and tables:
Connect to the PostgreSQL instance:
psql postgres://postgres:postgres@rails-todo.local.tembo.io:5432
List all databases:
SELECT datname FROM pg_database;
Connect to your application’s development database:
\c todolist_development
List the tables:
\dt
For a detailed guide on building a TodoList with Rails, you can refer to this Codecademy article: Building a ToDoList with Rails.