Building a JSON:API endpoint in Rails
A versioned API controller that paginates, eager-loads, and serializes articles while avoiding N+1 queries.
https://t.co/vVpKgGlD7D
#ruby#rubyonrails
The private `pagination_meta` reads Kaminari's paging methods off the scope to build a tidy metadata hash, giving clients current page, neighbors, and totals in one consistent shape.
The single article is serialized with a richer `include` list โ down to `comments.reactions` โ so the response carries the full nested graph without extra round trips.
`show` preloads the same associations plus comment reactions, then `find` looks up a single article by `params[:id]`, again loading everything up front to keep queries flat.
`ArticleSerializer` renders the collection as JSON:API, explicitly including author, categories, and nested comment authors, and attaching pagination details via `meta`.
`.page(params[:page]).per(25)` is Kaminari syntax that slices the result set into pages of 25, reading the requested page straight from the query params.
The query starts from the `published` scope, then `includes` eager-loads authors, categories, comments with their authors, and attached cover images โ preventing N+1 queries โ before ordering newest first.
The controller lives under `Api::V1` and inherits from `BaseController`, namespacing the endpoint so a future `V2` can evolve independently. `index` lists articles.
Live-updating comments with Turbo in #rubyonrails
A Comment model pushes its own creates, updates, and deletes to subscribers over Turbo Streams.
https://t.co/eLHwbJiY05
Writing a custom hostname validator in #rubyonrails. A reusable ActiveModel validator that checks a hostname's length, labels, and structure against RFC-style rules. https://t.co/NhA2vB9Vhl
Any #photographers here? Come and see my latest project: ShutterClick - Expert photo critique, on demand.
Scored ยท genre-calibrated ยท EXIF-aware
https://t.co/78F32XFArt
New users get 3 free critiques. If you'd like to get invite with 6 free critiques, let me know. #photography