A minimal Rails-like framework built from scratch to understand how Rails and other web frameworks operate under the hood.
Tinyrails implements the core pieces of a web framework:
- Rack integration - Connects to web servers through the Rack interface
- Routing - Maps URLs to controller actions (e.g.,
/tweets/showroutes toTweetsController#show) - Controllers - Handle requests and render views with ERB templating
- Models - Basic JSON file-based persistence with find and query methods
Add this line to your application's Gemfile:
gem 'tinyrails'Or install it directly:
gem install tinyrailsControllers inherit from Tinyrails::Controller and define action methods:
class TweetsController < Tinyrails::Controller
def show
render :show
end
endThe render method looks for views in app/views/{controller_name}/{action}.html.erb.
FileModel provides basic database operations using JSON files:
# Find a record by ID
tweet = FileModel.find(1)
# Get all records
tweets = FileModel.all
# Access attributes
tweet["content"]
tweet["author"] = "New Author"Records are stored as JSON files in app/db/{table_name}/{id}.json.
The router parses the URL path to determine which controller and action to call:
/tweets/show→TweetsController#show/users/index→UsersController#index
- Ruby >= 3.1.0
MIT