Rails and Postgres: How to test if your index is used as expected
Rails and Postgres index usage can be verified by running the generated SQL with EXPLAIN ANALYZE and temporarily disabling sequential scans.
HTML: Making browsers wrap long words
Long words can overflow layouts when browsers wrap only at word boundaries. CSS hyphenation, soft hyphens, <wbr>, and overflow-wrap offer different control levels.
JavaScript: Testing the type of a value
JavaScript value checks are inconsistent across primitives, objects, arrays, null, undefined, and NaN; the right test depends on whether you need type, instance, or property presence.
RSpec: Run a single spec (Example or ExampleGroup)
Limit a test run to one example or group with :focus, fit, fdescribe, or fcontext; unfocused suites fall back to running everything.
Capybara: Accessing the parent of an element
Capybara can move from a selected node to its parent with find(:xpath, '..'), useful for checking surrounding links or containers in tests.
Fixing flaky E2E tests
E2E tests often fail from race conditions between browser, app and test code; stabilizing them means synchronizing actions, retries and animations.
Be careful to use correct HTTP status codes for maintenance pages
Wrong status codes on maintenance pages can deindex sites or cache bad redirects. 503 Service Unavailable with Retry-After preserves SEO during temporary downtime.
Be very careful with 301 and 308 redirects
301 and 308 redirects can be cached by browsers indefinitely without cache control, making later changes impossible unless users clear their cache.
RSpec: How to define classes for specs
RSpec constants declared in specs leak into the global namespace, risking name collisions and brittle tests. Use stub_const, a Class.new variable, or self:: to keep helper classes isolated.
Dealing with I18n::InvalidPluralizationData errors
Rails can raise I18n::InvalidPluralizationData when a localized association name is looked up as model data. Adding the missing attribute translation or a matching one key fixes the error.
Rspec: around(:all) and around(:each) hook execution order
RSpec hook order matters when around(:all) and around(:each) wrap setup and teardown; their execution timing differs from before and after hooks.
How to use a local gem in your Gemfile
Use a local gem copy in Gemfile to test code changes immediately and debug or modify the gem without publishing. Avoid committing local paths because they break for other developers.
Caution when using the || operator to set defaults
|| can overwrite valid falsy values like false, 0, and '' when setting defaults; use nil or null checks, fetch, or nullish coalescing instead.
Rails: How to write custom email interceptors
Global mail interception in Rails can prefix subjects by environment and redirect staging mail to a fallback address unless recipients are allowlisted.
Working with or without time zones in Rails applications
Rails time handling is error-prone because Time.now and Time.current can differ. A single-time-zone setup needs matching Active Record and time zone configuration.
Using ActiveRecord with threads might use more database connections than you think
ActiveRecord threads can open one database connection per thread, quickly exhausting server limits. Rails reuses and releases connections automatically, but manual cleanup is sometimes needed.
Storing trees in databases
Tree data in relational databases can be stored with parent links, paths, nested boundaries, or closure tables; the choice trades write cost against read speed.
Running external commands with Open3
Reliable process execution in Ruby needs clean output capture, status checks, and safe handling of stdin, environment variables, and long-running commands.
How to search through logs on staging or production environments
Finding a request in staging or production logs often requires searching several servers and archived files; grep or zgrep can query current and zipped logs.
Git stash: Working with old entries
Older git stash entries can be inspected, applied, popped, or dropped by reference; patch views and partial restores help recover changes selectively.
How to tackle complex refactorings in big projects
Large refactorings risk breaking tests, blocking releases, and entangling unrelated changes; breaking work into small green steps keeps long-running project changes manageable.
It's OK to put block elements inside an <a> tag
HTML5 allows an <a> tag to wrap block content like paragraphs, lists, and sections, making whole regions clickable without invalid markup.
Summarizing heredoc in Ruby and Rails
Heredoc indentation and newline handling in Ruby and Rails varies by syntax and helper. <<~, strip_heredoc, and squish control unindentation and whitespace cleanup.
Capybara: Find an element that contains a string
Capybara can locate DOM nodes by text content using text: with a selector or regular expression, avoiding unsupported CSS string-matching selectors.