Merging two arbitrary ActiveRecord scopes

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

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.

Error handling and reporting with Rails

Rails exception handling can either crash requests, hide actionable errors, or spam trackers; ExceptionApp, DebugExceptions, and the error reporter shape responses, logging, and notifications.

Guide to localizing a Rails application

Rails app localization affects text, URLs, formats, images, caching, and time zones; estimating effort means checking each layer for language-sensitive behavior.

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.

Don't mix Array#join and String#html_safe

Mixing safe and unsafe HTML strings with Array#join breaks Rails output safety and can trigger incorrect escaping or unsafe rendering.

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.

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.

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.

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.

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

PostgreSQL: Difference between text and varchar columns

PostgreSQL character columns differ mainly in declared limits, not speed; unbounded varchar and text behave alike in Rails 4+, though some tools still render them differently.

Taking screenshots in Capybara

Capybara test failures can save screenshots and HTML automatically, with manual capture also available through save_and_open_page, save_screenshot, or Rails ScreenshotHelper.

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.

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

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.

Rails: Handling actions that need to happen after all transactions

ActiveRecord.after_all_transactions_commit runs work only after every open transaction commits, or immediately when none is open. It suits side effects like email delivery after persisted state changes.

Rails: Testing exceptions with the rescue_responses setting

Rails 7.2 changes show_exceptions defaults in tests, so rescued RecordNotFound often becomes a 404 response instead of a raised exception.

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.