The Rails core team secret weapon: a one file Rails app with SQLite
Ruby on Rails insiders often work with quick experiments and short iterations to quickly validate ideas and check bugs in the framework. Here's how.
Rails made SQLite a first-class database long before the current hype cycle, but the thing that really makes the core team’s eyes light up is more subtle than “production-ready”: you can fit an entire Rails app into a single file. No app/, no config/, no db/migrate/. One .rb file. Boot it, hit it, done.
This isn’t a toy. It’s the “one-person framework” philosophy pushed to its logical extreme, and it actually runs. Everything below works on Rails 5.
Here’s a complete, runnable one-file Rails app I wrote, with the ERB template embedded as a multiline string and SQLite handling persistence.
# one_file_rails.rb
require "rails"
require "action_controller/railtie"
require "active_record/railtie"
require "sqlite3"
class OneFileApp < Rails::Application
config.eager_load = false
config.secret_key_base = "one_file_secret_key_base_for_demo_only"
config.logger = Logger.new($stdout)
config.log_level = :warn
end
ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: ":memory:"
)
ActiveRecord::Schema.define do
create_table :notes, force: true do |t|
t.string :title
t.text :body
t.timestamps
end
end
class Note < ActiveRecord::Base
end
NOTES_TEMPLATE = <<~ERB
<!DOCTYPE html>
<html>
<head>
<title>One-File Rails</title>
<style>
body { font-family: system-ui, sans-serif; max-width: 720px; margin: 2rem auto; padding: 0 1rem; background: #fafafa; }
h1 { color: #c0392b; }
.note { background: white; border-left: 4px solid #c0392b; padding: 1rem; margin: 1rem 0; border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
form { background: white; padding: 1.5rem; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
input, textarea { width: 100%; padding: 0.5rem; margin: 0.5rem 0; border: 1px solid #ddd; border-radius: 4px; box-sizing: border-box; }
button { background: #c0392b; color: white; border: none; padding: 0.6rem 1.5rem; border-radius: 4px; cursor: pointer; font-weight: 600; }
button:hover { background: #a93226; }
.meta { color: #888; font-size: 0.85rem; }
</style>
</head>
<body>
<h1>🔥 One-File Rails + SQLite</h1>
<p>This entire app lives in a single Ruby file. No app directory. No migration files. Just one file and one in-memory SQLite database.</p>
<form action="/notes" method="post">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
<input type="text" name="note[title]" placeholder="Note title" required>
<textarea name="note[body]" placeholder="Write something..." rows="3"></textarea>
<button type="submit">Create Note</button>
</form>
<% @notes.each do |note| %>
<div class="note">
<h3><%= note.title %></h3>
<p><%= note.body %></p>
<span class="meta"><%= note.created_at.strftime("%H:%M:%S") %></span>
</div>
<% end %>
</body>
</html>
ERB
class NotesController < ActionController::Base
def index
@notes = Note.order(created_at: :desc)
render inline: NOTES_TEMPLATE, layout: false
end
def create
Note.create!(params.require(:note).permit(:title, :body))
redirect_to "/"
end
end
Rails.application.routes.draw do
root "notes#index"
resources :notes, only: [:create]
end
Rails.application.initialize!
require "rack"
Rack::Handler::WEBrick.run(Rails.application, Port: 3000)
Save that as one_file_rails.rb, make sure you have the rails (~> 5.0), sqlite3, and webrick gems available, then:
ruby one_file_rails.rb
Open localhost:3000. You have a web app that creates notes, persists them to SQLite, ships CSRF protection, and runs the full Rails middleware stack. All in one file.
ERB as a multiline string: why this feels so good
Cramming an ERB template into a <<~ERB heredoc looks like a step backward, but it exposes something Rails deliberately hides in a normal project: a template is just a string, and rendering is just ERB.new(string).result(binding).
In a conventional Rails app, that fact is buried under the filesystem, view resolution, and the render call chain. When you write the template as a multiline string, everything becomes naked. That one line render inline: NOTES_TEMPLATE, layout: false tells you plainly that views aren’t magic. For teaching, writing, demos, and even debugging weird view-layer bugs, that transparency is priceless.
It also forces the template and the instance variables it depends on into the same field of view. Where does @notes come from? A few lines below, in NotesController#index. No cross-file jumping, no “which before_action set this?” confusion.
The real advantages of this setup
Zero startup cost, zero environment drift
The slowest part of creating a conventional Rails project is rarely writing code, it’s getting code to run. bundle install, rails db:create, rails db:migrate, checking database.yml, confirming the Ruby version matches. The one-file app compresses all of that into a single ruby one_file_rails.rb. With SQLite in :memory:, nothing even hits disk. For quickly validating an idea, reproducing a bug, or demoing a concept to a colleague, the speed difference is an order of magnitude.
SQLite’s “network tax” drops to zero
When your database lives inside your application process, every query is a direct system call: no TCP round trips, no connection pool waits. In a one-file demo, that latency advantage is magnified: you don’t even need a database file, everything happens in memory. It’s also a beautiful reminder that SQLite has always been a legitimate choice, not a stepping stone you outgrow.
Sharing at its simplest
One file plus one SQLite file (if you’re not using :memory:) is the whole thing. You can zip it or put in a Github gist and start collaborating around with teammates and other contributors.
Where the boundary is
This isn’t a suggestion to convert your production SaaS into a single file. Rails’ directory structure exists for reasons: code organization, team collaboration, autoloading, the asset pipeline. The one-file app is a tool, not an architecture.
Its use cases are crisp: teaching demos, rapid prototypes, reproducing gem-level bugs, runnable examples for technical articles, and interviewing candidates on their Rails fundamentals. In those scenarios, it’s the sharpest knife in the drawer.
The real signal here is this: Rails’ abstractions are layered, and you get to choose which layer you work at. A conventional project sits at the highest abstraction layer, enjoying convention over configuration. A one-file app sits at the lowest, enjoying total control and transparency. A mature Rails engineer should move fluidly between those two extremes, not just sit in the middle layer waiting for rails new to arrange everything.
Go run that file. You’ll come away with a new understanding of what Rails actually is.