Ruby on Rails

Ruby Framework

Ruby on Rails Documentation

Overview

Ruby on Rails is a full-stack web framework written in Ruby. Alkimist provides complete support for Rails applications with automatic configuration, database migrations, and production optimizations.

Project Structure

A typical Rails application structure:

text
app/
  controllers/
  models/
  views/
config/
  routes.rb
  database.yml
Gemfile

Health Check Endpoint

Rails applications must implement a /up endpoint that returns a simple health check response. Here's how to implement it:

Rails 7.1+ includes a built-in health check endpoint. Add this to your config/routes.rb:

ruby
# config/routes.rb
Rails.application.routes.draw do
  # Your existing routes...

  # Health check endpoint
  get "up", to: "rails/health#show", as: :rails_health_check
end

This will automatically return 200 OK if the application boots successfully.

Option 2: Custom Health Check Controller

If you need a custom health check, create a controller:

ruby
# app/controllers/health_controller.rb
class HealthController < ApplicationController
  skip_before_action :verify_authenticity_token

  def show
    render plain: "ok", status: :ok
  end
end

And add the route:

ruby
# config/routes.rb
get "up", to: "health#show"

Option 3: Minimal Route

For the simplest implementation:

ruby
# config/routes.rb
get "up", to: proc { [200, {}, ["ok"]] }

Database Configuration

Alkimist automatically detects your database from your Gemfile. Supported databases:

  • PostgreSQL: gem 'pg'
  • MySQL: gem 'mysql2'
  • SQLite: gem 'sqlite3'

Environment Variables

Set your environment variables in the project settings. Common Rails environment variables:

  • RAILS_ENV=production
  • RAILS_MASTER_KEY (for encrypted credentials)
  • DATABASE_URL (automatically configured)
  • REDIS_URL (if using Redis)

Deployment

Alkimist automatically:

  1. Detects your Rails version from Gemfile
  2. Generates appropriate Dockerfile
  3. Configures Kamal deployment files
  4. Sets up database migrations
  5. Configures asset pipeline

Example Project

A minimal Rails application with health check:

ruby
# config/routes.rb
Rails.application.routes.draw do
  get "up", to: "rails/health#show", as: :rails_health_check
  root "home#index"
end

That's it! The health check endpoint will be available at /up and return 200 OK when your application is running.