CSS has a built-in clearfix
Floated children can collapse their container, but display: flow-root creates a new block formatting context without clearfix hacks. IE11 lacks support.
Difference between respond_to/format and params[:format]
Non-HTML Rails responses can differ from params[:format]; respond_to also matches MIME negotiation, so authorization should not depend on a URL suffix alone.
7 Rules for Creating Gorgeous UI
Practical UI design tricks for non-designers: improving layout, typography, contrast, and image overlays to make screens look polished.
OpenAI TTS: How to generate audio samples with more than 4096 characters
OpenAI TTS requests are capped at 4096 characters, so longer text needs chunking and MP3 merging to generate complete audio.
Capistrano: creating a database dump if migrating
Create a database dump only when Capistrano will run Rails migrations, using conditional migration checks and a deploy hook.
Rails: Pluck across associated tables
pluck can fetch values from joined tables in one query, returning columns from associated records without loading full Active Record objects.
RailsStateMachine 2.2.0 released
RailsStateMachine 2.2.0 adds :prefix for multiple state machines on one model and fixes repeated RailsStateMachine::Model inclusion resetting existing machines.
Livereload + esbuild
Live CSS and JS reloading in Rails with esbuild is awkward because generated assets change on every build. A guard-livereload plus livereload-js setup can avoid full-page reloads for stylesheet changes.
Webpack: How to split your bundles
Large JavaScript libraries can bloat the main bundle; import() lets webpack load them asynchronously and keep rarely used code out of the initial payload.
MySQL: CONCAT with NULL fields
CONCAT() with NULL returns NULL in MySQL, so text can disappear unexpectedly; CONCAT_WS('', ...) treats NULL as empty strings, while PostgreSQL concatenation ignores NULL.
Simple database lock for MySQL
MySQL can coordinate multiple Rails processes with a database-backed mutex when code must not run concurrently. It is for model-level synchronization, not record locking.
Javascript: Avoid using innerHTML for unsafe arguments
Unsafe innerHTML use can introduce XSS when user content is inserted into HTML. textContent or text keeps values escaped for safe text updates.
Transfer records to restore database entries (with Marshal)
Move exact database records between systems by serializing Ruby objects with Marshal and Base64 when a direct export/import needs to preserve IDs and state.
RSpec: Messages in Specific Order
ordered in RSpec verifies that mocked messages arrive in a specific sequence, helping catch incorrect call order in tests.
How to define constants with traits
Traits can leak constant values across including classes when constants are assigned inside as_trait; binding them to self keeps each class’s constant separate.
Event delegation (without jQuery)
Single-listener event handling can cut setup cost and support dynamically added elements, but it can slow fast events and limits bubbling control.
How to (and how not to) design REST APIs · stickfigure/blog Wiki
Common REST API design mistakes keep recurring, and a set of practical best practices helps avoid brittle, confusing interfaces.
RSpec: Composing a custom matcher from existing matchers
Compose a custom RSpec matcher from existing matchers to reduce repeated expectations and keep failure messages informative.
Ruby: Using `sprintf` to replace a string at fixed named references
Named placeholders in sprintf and format make long strings with several values easier to build, especially URLs and API endpoints with fixed parameters.
`simple_format` does not escape HTML tags
simple_format does not escape unsafe HTML and sanitizes generated paragraphs instead. Escape user input first or customize sanitize_options in Rails 7.1.
How to use Rails URL helpers in any Ruby class
Accessing Rails path helpers from plain Ruby classes can be awkward, and including all route helpers risks method clashes. Delegating url_helpers exposes only the needed path methods.
Using Rationals to avoid rounding errors in calculations
Exact fractions in Ruby prevent rounding drift in unit conversions and tests, but mixing Rational with BigDecimal or floats can still reintroduce inaccuracies.
List of default browser stylesheets
Browser default styles affect pages with no CSS and differ between Chrome, Firefox, and Safari, making layout comparisons and reset strategies inconsistent.
A very compatible default CSP for Rails projects
Keep Rails apps protected with a minimally restrictive Content Security Policy that blocks injected scripts while preserving compatibility with nonces and strict-dynamic.