Querying model errors in Rails 4

ActiveModel::Errors behaves like a hash for storing and querying validation messages on model attributes in Rails 4.

Creating a Rails application in a single file

Running Rails in one file is useful for quick experiments, debugging bugs, or embedding an app in tests, but version and dependency drift can cause surprises.

How to iterate over all ActiveRecord models

Rails maintenance scripts can loop through every loaded ActiveRecord model for migrations or data fixes. eager_load! and ApplicationRecord.descendants help avoid missing models.

Ruby: Replacing Unicode characters with a 7-bit transliteration

Unicode characters can break 7-bit string transport; transliteration to Low-ASCII keeps text usable where escaping is not possible.

Rails: Overwriting default accessors

Customizing Active Record attribute readers and writers can trim or normalize values before persistence, while direct attribute storage bypasses other overridden behavior.

Rails: Concurrency-safe API request counting with `upsert`

Lost updates make Ruby-side counter increments unsafe under concurrent API traffic; a Postgres upsert with a unique index performs atomic request counting.

How to disable logging for ActiveStorage's Disk Service routes

ActiveStorage disk-service requests can clutter development logs with redundant route, record-load, and URL-generation messages. Selective silencing keeps Rails output readable.

ActiveRecord: validate_uniqueness_of is case sensitive by default

Rails uniqueness validation treats username and USERNAME as different by default, which can conflict with MySQL’s case-insensitive comparisons and unique indexes.

RSpec: Where to put shared example groups

Shared example groups need a clear home in RSpec, since the default rspec-rails layout does not provide one. Organizing them in dedicated shared_examples folders keeps them reusable and easy to load.

Rails 7 adds #caching? and #uncacheable!

Rails 7 fragment caching gets #caching? and #uncacheable! to detect cache context and prevent accidental caching of helpers or partials that must stay dynamic.

Ruby: Referencing global variables with the built-in English library

Ruby’s special global variables are harder to read and can fail without require 'English', especially in Rails where the library is not loaded by default.

Embedding Pannellum (360° panorama viewer) in an esbuild/Rails app

Pannellum offers a lightweight equirectangular panorama viewer for Rails and esbuild, but its npm package only attaches window.pannellum; container sizing and blob: CSP need care.

Rails: Assigning associations via HTML forms

Rails forms can assign tag associations in several ways, from array columns to join models; nested attributes keep tag changes in one transaction.

Tagging in Rails 4 using Postgres Arrays

Store multiple labels in one field and query records by any or all of them with PostgreSQL array operators and a GIN index in Rails 4.

Do not use "permit!" for params

params.permit! marks all request parameters as safe and mutates the original object, risking mass assignment vulnerabilities later in Rails code.

SAML Single Logout (SLO)

SAML logout can be initiated by the service provider or identity provider, with browser redirects or backchannel POSTs; devise_saml_authenticatable needs specific Rails and Keycloak logout handling.

Using multiple MySQL versions on the same linux machine using docker

Run several MySQL releases on one Linux host with Docker instead of mysql-sandbox, and connect Rails to each instance through a separate TCP port.

Rails: Testing file downloads with request specs

File downloads are slow and fragile to test through Capybara. Request specs make exports fast, stable, and easy to verify, with a small end-to-end check for the link.

Rails: Prefer parsing dates with Date.strptime()

Date.parse guesses date formats and can accept invalid input, producing unexpected dates. Date.strptime validates against an explicit pattern and avoids ambiguous parsing.

How to query PostgreSQL's json fields from Rails

PostgreSQL json fields store flexible data, but Rails lacks built-in querying sugar. Matching nested values requires manual SQL operators and text extraction.

Managing Rails locale files with i18n-tasks

i18n-tasks helps keep Rails locale files complete by finding missing and unused translation keys and reducing manual YAML bookkeeping.

Rails 4.1+: New locale files require a Spring restart

Rails 4.1 development can ignore newly added I18n YAML files because Spring caches the load path; restarting Spring makes new translations appear.

Rails < 5: How to get after_commit callbacks fired in tests

Transactional test fixtures can suppress after_commit callbacks in Rails, preventing email jobs and other post-save work from running. Rails 5 fixes this; older versions can use test_after_commit.

Rails: Encrypting your database information using Active Record Encryption

Rails 7 app data can be stored as encrypted attributes with deterministic lookup support, but search, grouping, and bulk updates become limited.