Checklist: Using Carrierwave in a Rails project
Checklist for CarrierWave edge cases beyond the default Rails setup: secure URLs, image resizing, metadata handling, file validation, and efficient processing.
PSA: "index: true" in Rails migrations does not work as you'd expect
index: true is silently ignored in some Rails migration methods like add_column, so missing database indexes can go unnoticed and hurt query performance.
Rails disables CSRF protection in tests
Rails test environment turns off CSRF checks by default, so missing authenticity tokens can hide broken POST flows. Enabling forgery protection in JavaScript tests catches these failures.
Detect the current Rails environment from JavaScript or CSS
Expose Rails.env on <html> to branch JavaScript and CSS by environment, making Selenium- and test-specific behavior easy to toggle.
How to combine "change", "up", and "down" in a Rails migration
Rails migrations need path-specific logic for data updates while keeping rollback support. reversible, up_only, and reverting? handle direction-dependent SQL safely.
How to organize monkey patches in Ruby on Rails projects
Rails projects accumulate small monkey patches for gems and core classes; grouping them under lib/ext by gem or namespace keeps config/initializers tidy and loading predictable.
Rails: Preloading associations in loaded records
Preloading nested associations on already loaded ActiveRecord objects avoids extra queries when rendering deeply related data and fits legacy Rails models via preload_associations.
Rails developers: Have better context in Git diffs
Git can show the wrong surrounding code in Ruby diffs unless file types are mapped to better hunk headers. Custom diff drivers and xfuncname improve context for Rails, RSpec, and Cucumber files.
Auto-generating plain-text bodies for HTML e-mails in Rails apps
HTML e-mails in Rails need a plain-text part to avoid spam penalties; premailer-rails can generate it automatically and be tuned for line length and formatting.
Rails credentials: Always use the bang version
Missing secrets can stay unnoticed in some environments and break behavior later. Using ! on Rails.application.credentials and Rails secrets raises immediately when a value is absent.
How to make your application assets cachable in Rails
Rails asset URLs need fingerprints or timestamps to let browsers cache images, stylesheets, and scripts long-term without serving stale files after updates.
How to Work With Time Zones in Rails
Rails uses configurable time zones, while Ruby time APIs follow the server zone and can return wrong results. Time.zone keeps date and time handling consistent.
Using ActiveRecord with threads might use more database connections than you think
ActiveRecord threads can open one database connection per thread, quickly exhausting server limits. Rails reuses and releases connections automatically, but manual cleanup is sometimes needed.
Rails 8: The db:migrate task might not run all migrations in db/migrate/ anymore
rails db:migrate on fresh databases now loads db/schema.rb or db/structure.sql first, which can skip data-manipulation migrations and leave state incomplete.
Rails I18n scope for humanized attribute names
Custom attribute labels in Rails can be stored in locale files and reused by human_attribute_name and error messages instead of duplicating names in code.
How to debug file system access in a Rails application
Rails apps can make hidden file checks that slow requests, especially on networked storage. strace reveals unnecessary stat calls and other system calls.
Rails and Postgres: How to test if your index is used as expected
Rails and Postgres index usage can be verified by running the generated SQL with EXPLAIN ANALYZE and temporarily disabling sequential scans.
Different ways to set attributes in ActiveRecord
ActiveRecord attribute assignment methods differ in persistence, validations, callbacks, timestamp updates, and readonly handling across Rails versions.
Implementing authentication and authorization for ActiveStorage blobs/files
Rails ActiveStorage direct uploads are public by default, so unauthenticated users can flood storage and access sensitive blobs without ownership checks.
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.
Rails: Use fixture helpers like `users(:alice)` in the Rails console
Rails console fixture lookups are awkward when only fixture names are known; a small initializer adds users(:alice)-style helpers for loaded fixture records.
How to upgrade Rails: Workflow advice
Upgrading Rails across major versions needs staged updates, compatible Ruby and gem versions, and repeated checks in console, server, tests, and config defaults.
Rails console tricks
Quick console shortcuts for changing receiver context, inspecting objects, making requests, using helpers, and querying schema in a Rails session.