Testing ActiveRecord callbacks with RSpec

Database-backed RSpec checks for ActiveRecord lifecycle behavior are more reliable than stubs when verifying side effects like automatically creating associated records.

Generate a strong secret from the shell

Strong secrets for sessions and secret_key_base can be generated from the shell with apg or bin/rails secret.

How to fix: Pasting in IRB 1.2+ is very slow

Long pastes in irb 1.2+ can become extremely slow because multiline mode and syntax highlighting add heavy overhead. Disabling multiline restores fast pasting.

Shortcuts for getting ids for an ActiveRecord scope

ActiveRecord relations can return only primary keys instead of full records, reducing query payload when just record identifiers are needed.

Don't use migrations to seed default data

Seeding rows in a Rails migration breaks tests that expect an empty database and creates maintenance pain. Use db/seed.rb or a script in lib/scripts for default application data.

When reading model columns during class definition, you must handle a missing/empty database

Class definition code that inspects model columns can crash startup when the database is missing or empty, blocking db:create and db:migrate.

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.

How to silence Puma for your feature tests

Feature specs can print noisy Puma startup logs when Capybara launches the test server. Setting Capybara.server = :puma, { Silent: true } suppresses the output.

Detecting if a Ruby gem is loaded

Activated gems can be checked through Gem.loaded_specs, and required libraries can be detected with defined? on a constant they define.

Why two Ruby Time objects are not equal, although they appear to be

Time comparisons can fail in tests because Ruby keeps subsecond fractions even when the printed values look identical.

Configuring Git with .gitconfig

Simple Git configuration for new developers: aliases, merge and rebase defaults, better diffs, and GitLab push shortcuts.

ES6 imports are hoisted to the top

ES modules are hoisted, so import order in source can differ from execution order and break code that depends on globals like $.

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.

How to avoid multiple versions of a package in yarn

Duplicate package versions in Yarn can break shared globals like window.jQuery, leaving plugins such as datepicker unavailable. resolutions can force one version across dependencies.

Vortrag: Content Security Policy: Eine Einführung

Content Security Policy schützt Webseiten vor XSS, indem der Browser erlaubte Quellen für Skripte, Styles, Bilder und Verbindungen streng einschränkt.

Find an ActiveRecord by any column (useful for Cucumber steps)

Finds a record by any string or number across columns, making Cucumber step definitions more flexible. The bang variant raises ActiveRecord::NotFound when nothing matches.

Detect mobile or touch devices on both server and client

Shared device detection on Rails server and browser client keeps touch-specific behavior available beyond CSS-only or feature-detection hacks.

ActiveStorage: How to add a new preprocessed named version

Preprocessed ActiveStorage variants let avatars be generated ahead of time for faster display, but existing records need a one-time backfill after adding the named version.

Writing strings as Carrierwave uploads

CarrierWave needs a filename for string or stream uploads through ActiveRecord; a small StringIO wrapper with original_filename avoids TypeError and works with Zeitwerk.

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.

Managing chrome versions for selenium

Browser and driver mismatches can break Selenium tests; Selenium Manager can fetch matching Chrome and chromedriver versions automatically, though the first run is slower.

Unpoly: Loading large libraries on-demand

Large JavaScript libraries can be loaded only when needed to keep initial bundles small and avoid duplicate script execution, memory leaks, and repeated event handlers.

Don't assign time values to date attributes

Time values assigned to date fields can shift a day in non-UTC apps. Use Date.current or convert future times with to_date before saving.

In MySQL, a zero number equals any string

MySQL treats 0 = 'any string' as true, so mixed string-integer comparisons can match unexpected rows and bypass indexes; PostgreSQL rejects such comparisons.