How to use html_safe correctly

html_safe marks strings for unescaped insertion in Rails views, but does not unescape content; misusing it on user input can enable XSS.

Caching in Rails < 6.1 may down parts of your application when using public cache control

Public cache control can serve the wrong MIME type and enable cache poisoning when responses vary by Accept; Vary: Accept prevents stale or mismatched cached content.

How to: A thorough i18n completeness check in CI (Rails + i18n-tasks)

Rails i18n completeness can drift across tiers and locales; CI with i18n-tasks catches missing, unused, inconsistent, and normalized translation files.

Rails console tricks

Quick console shortcuts for changing receiver context, inspecting objects, making requests, using helpers, and querying schema in a Rails session.

Merging two arbitrary ActiveRecord scopes

Rails ActiveRecord::Relation#merge can silently drop conditions on the same column; a subquery keeps combined scopes unambiguous.

Popular mistakes when using nested forms

Common Rails nested form pitfalls include missing accepts_nested_attributes_for, wrong form helper scope, and lost parameters that prevent child records from saving.

Rails npm packages will use an uncommon versioning scheme

Rails npm packages need a version mapping from 4-part gem releases to npm’s 3-part semver, so package ranges keep working across patch and prerelease builds.

Isolated Rails databases for Git worktrees

Parallel Git worktrees can clash on shared Rails development and test databases. A small database.yml suffix per worktree isolates database names without affecting normal checkouts.

Make your CI config simpler with ActiveSupport::ContinuousIntegration

Rails 8.1 CI setup can be split into focused commands for tests, linting, and security checks, reducing local overhead while keeping full coverage in continuous integration.

Testing ActiveRecord validations with RSpec

Rails model validation tests can be written directly with record.validate and error checks, or shortened with shoulda-matchers for standard cases.

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.

Rails: Different flavors of concatting HTML safe strings in helpers

Different ways to build HTML-safe markup in Rails helpers affect readability, buffering, and XSS safety. concat, safe_join, capture, and html_safe each behave differently.

Cancelling the ActiveRecord callback chain

ActiveRecord callback chains can halt or roll back transactions differently across Rails versions, and accidental false returns may stop legacy callbacks.

How to define a table prefix for all Rails models in a namespace

Rails namespaces can produce doubled table prefixes when table_name_prefix is set on individual models. Defining it on the namespace module keeps nested model table names correct.

How to create Rails Generators (Rails 3 and above)

Rails generator creation and customization rely on Thor-based classes, template lookup, hooks, and customizable output for models and controllers.

Debugging Rails Active Jobs with the Vanilla Adapters

Rails jobs can be hard to inspect because adapters behave differently in development, test, and production. Logging, synchronous execution, and queue tables help trace failures and pending work.

Upgrading Rails 2 from 2.3.8 through 2.3.18 to Rails LTS

Rails 2.3.x upgrades fix security vulnerabilities and API changes across patch levels, with extra CSRF, XSS, and JSON gem updates needed on some releases.

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

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.

How Rails chooses error pages (404, 500, ...) for exceptions

Rails maps unhandled exceptions to HTTP status codes and error pages via action_dispatch.rescue_responses, and custom classes can be treated as 404 or 500 responses.

Rails: When to use :inverse_of in has_many, has_one or belongs_to associations

inverse_of lets Rails treat both sides of an association as the same in-memory object, reducing duplicate loads and fixing bi-directional association behavior.

Rails: Redirecting the Logger output temporary aka showing Rails logs in the console

Temporarily route Rails and Active Record logging to STDOUT to inspect database and framework output directly in the console.

Your database tables should probably have timestamps

Missing created_at and updated_at columns make record history harder to trace and bug reports harder to investigate. Rails migrations can add and backfill timestamps for old tables.

How to add esbuild to the rails asset pipeline

Migrating a Rails app from Sprockets-only asset handling to esbuild adds modern JavaScript bundling and can surface path, font, and Sass compatibility issues.