NEGABARO Rails

An encyclopedia of essential concepts for Rails development.

๐Ÿ—„๏ธ Models & Database

๐Ÿ’Ž

ActiveRecord

ORM โ€” manipulate databases with objects

Object-Relational Mapping. Auto-maps Ruby objects to DB tables, enabling CRUD via Ruby methods without writing SQL.

๐Ÿ“ฆ

Migrations

Version control database schema with code

Define DB table creation/modification/deletion in Ruby code, executed chronologically for schema version control. Track and rollback DB changes like Git.

๐Ÿ”—

Associations

has_many, belongs_to โ€” defining relationships between models

Declaratively define model relationships with belongs_to, has_many, has_one, has_many :through. Auto-connected when following foreign key conventions.

โœ…

Validations

Ensure data integrity at the Model level

Declare validations on models with the validates macro. Various checks (presence, uniqueness, length, format) run before DB save.

๐Ÿช

Model Callbacks

Hooks that auto-execute before/after save/delete

Hook into model lifecycle events (before_save, after_create, before_destroy) to auto-execute logic at specific points.

๐Ÿ”Ž

Scopes & Query Interface

Name and manage reusable queries

Name frequently used query conditions with scope macro for reuse. Chainable for readable complex queries.

โš ๏ธ

N+1 Query Problem

Performance enemy โ€” solving with includes

Individually querying associated data in loops causes 1 (list) + N (each association) queries. Reduce to 2 queries with includes/preload/eager_load.

๐Ÿงฉ

jsonb and store_accessor

Treat a PostgreSQL jsonb column like a model attribute

jsonb is a PostgreSQL column type that stores JSON as binary. With store_accessor, you pack multiple values into one jsonb column and read/write them like regular columns.

๐Ÿ”€

find_or_initialize_by vs create_or_find_by

Why RecordNotUnique happens โ€” the order of find and create

The two methods run find and create in opposite order. find_or_initialize_by SELECTs first, create_or_find_by INSERTs first. If concurrent requests throw RecordNotUnique, switch to the latter.

๐Ÿš€ Advanced

โณ

Background Jobs

Active Job + Sidekiq โ€” process heavy tasks asynchronously

Process time-consuming tasks like email delivery, file processing, and external API calls asynchronously in background queues. Users get immediate responses.

๐Ÿ’€

Sidekiq: Deploys and the Async Job Pitfall

SIGTERM/SIGKILL โ€” why long Sidekiq jobs die on every deploy

Async jobs can vanish entirely or get stuck forever in \"running\" state depending on deploy timing. Understanding the difference between SIGTERM (graceful) and SIGKILL (forced), how Sidekiq handles graceful shutdown, and the limits of OSS reveals why these incidents happen.

๐Ÿ“ก

Action Cable

Rails built-in WebSocket โ€” real-time features

WebSocket framework built into Rails that pushes real-time data from server to client. Used for chat, notifications, and live updates.

๐Ÿ’จ

Caching

Dramatically improve response speed by reducing repeated computations

Cache DB queries and view rendering results with Fragment Caching, Russian Doll Caching, Low-Level Caching for 10x+ response speed improvement.

๐Ÿ“ฆ

Asset Pipeline & Vite

Frontend asset management for JavaScript, CSS, images

Bundle JavaScript/CSS/images with Sprockets (legacy), Webpacker (deprecated), Vite (modern) and optimize cache with fingerprinting.

๐Ÿšข

Kamal Deployment

Rails official deployment tool โ€” Docker-based zero-downtime deploys

Rails official deployment tool by DHH. Deploy to any VPS with Docker containers. For small servers like DigitalOcean, local build + push to registry is recommended.

๐Ÿ–ผ๏ธ

background-removal-js โ€” How AI Background Removal Works in the Browser

IS-Net model + ONNX Runtime Web + WebGPU โ€” client-side segmentation without a server

imgly/background-removal-js removes image backgrounds with AI in the browser, no server needed. Runs IS-Net (U-Net family) via ONNX Runtime Web with WebGPU acceleration. Resizes to 1024ร—1024 โ†’ model outputs alpha mask โ†’ applied to original.