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.
Know your Haml comments
Haml supports HTML comments that reach the browser and Ruby comments that stay server-side, with indentation errors causing confusing syntax failures.
Merging two arbitrary ActiveRecord scopes
Rails ActiveRecord::Relation#merge can silently drop conditions on the same column; a subquery keeps combined scopes unambiguous.
Testing if two date ranges overlap in Ruby or Rails
Date and time interval checks are easy to get wrong because partial, nested, and touching ranges all count as overlaps. A simple inclusive comparison works for Ruby and Rails.
Zeitwerk: How to collapse folders in Rails
Rails can keep subfolders for organization without turning them into namespaces; collapse lets nested files define top-level constants instead of modules.
How to: Upgrade CarrierWave to 3.x
CarrierWave 3.x changes upload allowlists, inactive versions, version recreation, and processing paths, breaking older uploader logic and custom transcoders.
Google Chrome: How to restore the old downloads bar
Chrome's old downloads bar offers faster access, visible progress, single-click opening, and easier drag-and-drop reuploads than the newer downloads dropdown.
Delivering Carrierwave attachments to authorized users only
Sensitive file attachments can be restricted to authorized users, or served from hashed public paths and expiring URLs for safer access without exposing direct storage locations.
Geordi hints
Quick Geordi command shortcuts for guided deployment, setup, security updates, tracker-based commits, and matching ChromeDriver installation.
Regular Expressions: Space Separators
\s misses non-breaking spaces in UTF-8 text; [[:space:]] and \p{Zs} match space separators more reliably, with encoding compatibility caveats.
Solving "TypeError (nil can't be coerced into Integer)" in the Rails console / IRB
Rails console assignments can print TypeError (nil can't be coerced into Integer) even when they succeed. The bug affects IRB with --nomultiline and is fixed in reline 0.2.0.
PSA: Be super careful with complex `eager_load` or `includes` queries
eager_load and includes can explode 1-n association queries into huge cross products, wasting memory. preload uses separate queries and avoids the row multiplication.
Ruby: `extend` extends the singleton class's inheritance chain
extend places module methods into a singleton class’s ancestor chain, which affects class methods, method lookup, and super behavior.
Debug MiniMagick calls in your Rails app
CarrierWave hides MiniMagick processing failures behind a generic error; enabling MiniMagick.logger.level = Logger::DEBUG reveals the underlying ImageMagick commands and helps trace the cause.