How to tell ActiveRecord how to preload associations (either JOINs or separate queries)

ActiveRecord association loading can use separate queries or joins, and includes may switch between them automatically. preload is the safest default for avoiding surprise eager loading behavior.

Capistrano: Speeding up asset compile during deploy

Reducing Capistrano deploy time by persisting asset compiler caches across releases can skip repeated Sprockets or Webpacker work. esbuild has no comparable cache directory.

How to find out which type of Spec you are

Runtime checks can identify the current RSpec spec type, letting shared setup run only for controller, helper, or request/response-aware examples.

Don't require files in random order

File loading order from Dir.glob can vary by file system and break code that depends on load sequence. Sorting the matched paths or using sort: false in Ruby 3 makes it predictable.

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.

Cucumber: Identifying slow steps that drag down your test speed

Cucumber test suites can hide slow steps that waste most runtime. --format usage measures step durations and highlights optimization candidates, especially when waiting assertions surface previous delays.

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.

Generating and streaming ZIP archives on the fly

Large ZIP downloads can start immediately without writing files to disk, using zip_tricks_stream for custom content or zipline for existing attachments.

Why has_many :through associations can return the same record multiple times

has_many :through can return duplicate records when multiple join rows point to the same target; :uniq or DISTINCT removes repeated results.

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.

Configuring Git with .gitconfig

Simple Git configuration for new developers: aliases, rebase defaults, diff tools, and GitLab push shortcuts for a cleaner workflow.

Rails Asset Pipeline: Building an Icon Font from SVG Files

Asset pipeline setups can still build an icon font from SVG files, but the workflow needs manual generation and stylesheet integration.

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.

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.

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.

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.

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.

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.

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 $.

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.

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.