rails

Secure password reset flow with signed tokens

Password reset workflows require careful security design to prevent account takeover. I generate time-limited, single-use tokens using Rails' signed_id feature which creates tamper-proof tokens without database storage. The token expires after a short

Keep navbar state across Turbo navigations with data-turbo-permanent

Some UI elements should survive navigation: a music player, a search input, or a navbar with an open dropdown. Turbo’s data-turbo-permanent lets you mark a DOM node that shouldn’t be replaced during visits. I use it carefully—permanent nodes can keep

Pundit for authorization and policy objects

Pundit provides simple, object-oriented authorization. Policies encapsulate authorization rules in plain Ruby classes. Each model gets a policy class defining who can perform actions. I use Pundit for fine-grained permissions—different users see diffe

Inline create form that prepends into a list with Turbo Streams

My favorite Hotwire demo is the classic “inline create” on an index page. The form sits at the top of the page. When submitted, the create action returns turbo streams that (1) prepend the new item into the list and (2) replace the form with a fresh,

Query objects for complex database queries

Query objects encapsulate complex database queries in reusable, testable classes. I use query objects when scopes become too complex or require parameters. Query objects compose smaller scopes, handle conditionals, and apply filtering logic. They're i

Counter Cache Repair Job (Consistency Tooling)

Counter caches drift (deleted records, backfills, manual SQL). A repair job that recomputes counts safely is invaluable. It’s the kind of operational code you’re glad you wrote the first time a dashboard is wrong.

Turbo Streams for real-time list updates

Turbo Streams enable surgical DOM updates from the server without writing JavaScript. After a successful form submission, instead of redirecting, I return a Turbo Stream response that appends, prepends, replaces, or removes specific elements. This is

Database transactions for data consistency

Transactions ensure that multiple database operations either all succeed or all fail together, preventing partial updates that leave data in inconsistent states. Rails provides ActiveRecord::Base.transaction which wraps a block of code in a database t

Scoped navigation inside a sidebar with Turbo Frames

Sometimes you want only part of the screen to navigate—like a sidebar list updating the main content. Turbo Frames can do this cleanly: render the sidebar normally, and make its links target a turbo_frame_tag called main. Clicking a link swaps the mai

Turbo Frames: inline “details drawer” without a SPA router

A common UI is a list on the left and a details panel (drawer) on the right. With Turbo Frames, each list item link can target a details frame. Clicking an item swaps the drawer content while leaving the list intact. The server still renders HTML, so

Decorator pattern with Draper for view logic

Draper decorators encapsulate view-specific logic, keeping models clean. Decorators wrap models, adding presentation methods without polluting domain logic. I use decorators for formatting, conditional rendering, helper delegation. Decorators access h

Cache Key Versioning with a Single “namespace”

When cache structures change, you want to invalidate safely without flushing the world. Use a namespace version key (per feature) and incorporate it into cache keys.