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.
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.
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.
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.
redirect_to and redirect
Rails URL redirects differ in status code, query-parameter handling, and security implications; choosing 301 or 302 affects browser behavior and search engine indexing.
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.
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.
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: 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.
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.
Advantages of using appname.daho.im:3000 over localhost:3000
Using separate local hostnames avoids cookie clashes and logouts when switching between web apps on Rails development servers.
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 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: 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.
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: Talking to the database without instantiating ActiveRecord objects
Direct SQL access can avoid the overhead of instantiating ActiveRecord objects, but skips validations, callbacks, and custom accessors.
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.
Ruby: How to measure code execution time in an IRB or Rails console
IRB and Rails console sessions can time code execution directly with measure; older versions can use Benchmark.measure for manual timing.
Supporting multiple SAML IdPs within a single Rails application
Multi-tenant Rails apps can use one OmniAuth setup for several SAML identity providers, loading the right configuration at runtime for secure SSO.
esbuild: Make your Rails application show build errors
esbuild watch errors stay hidden in the terminal while Rails keeps serving stale assets; writing them to a file lets the app render build failures in development.
How to debug issues with zeitwerk and Rails
Zeitwerk autoloading problems in Rails can be hard to trace during boot; Rails.autoloaders.log! and bin/rails zeitwerk:check help reveal constant-to-file mapping issues.
Your Rails sandbox console
rails console --sandbox lets you test database changes in a console session and automatically rolls them back on exit, while file and email actions remain permanent.