ActiveRecord: count vs size vs length on associations
size is usually the right way to count associated records in Rails; count can ignore loaded children, while length loads everything.
Working with or without time zones in Rails applications
Rails time handling is error-prone because Time.now and Time.current can differ. A single-time-zone setup needs matching Active Record and time zone configuration.
Lightning Talk: Coverage based Test Case Prioritization in Ruby on Rails
CLI test case prioritization for Ruby on Rails using coverage data can surface failing specs earlier and reduce regression testing time.
Rails: Fixing the memory leak / performance issues in prepend_view_path
prepend_view_path can leak memory and bypass template caching when called per request, causing slower rendering in multi-tenant Rails apps.
ActiveRecord: Creating many records works faster in a transaction
Bulk inserts into one table can be much faster inside a transaction; Rails 6+ also offers insert_all for a single multi-row INSERT without validations.
Rails: Configuring the default sorting behaviour
Default ordering in ActiveRecord queries falls back to id unless implicit_order_column is set, which can make first and other finder calls return a different record order.
Action Mailer Previews
Previewing Rails emails in the browser catches layout and content issues before delivery and helps keep mailer output aligned with expectations.
Automatic Log Rotation in Rails
Rails log files rotate automatically around 100 MB, and config.log_file_size lets you cap growth and keep logs manageable in development, test, or production.
ActiveRecord: Passing an empty array into NOT IN will return no records
Empty exclusion lists in NOT IN conditions can silently return no rows; where.not in Rails 4+ handles empty arrays safely.
Rails: Keeping structure.sql stable between developers
db/structure.sql can vary between developers because database or CLI tool versions differ, creating noisy diffs and merge conflicts in Rails projects.
Rails: Accessing strong parameters
Rails parameters need careful filtering before mass assignment or URL generation; expect, require, permit, slice, and except help avoid security issues and noisy extras.
Rails: Looking up constants by their name string
Rails constantize and safe_constantize turn strings into constants, but untrusted input can resolve dangerous classes; validate with an allowlist first.
How to speed up JSON rendering with Rails
Slow Rails JSON endpoints often waste time in JBuilder, loading full records, and Ruby object allocation. pluck, database aggregation, and cached materialized views can cut response time dramatically.
Rails: namespacing models with table_name_prefix instead of table_name
Rails namespaces can share a table name prefix, avoiding repeated self.table_name settings for each model and keeping nested models aligned with naming conventions.
How to: Rails cache for individual rspec tests
Rails caching can be enabled for a single RSpec example without changing global test settings. File and memory stores let cache behavior be verified in isolated tests, including parallel runs.
Escape a string for transportation in a URL
Safely transporting arbitrary text in URLs requires percent-encoding reserved characters like & and =; Rails helpers do this automatically, while manual URLs need CGI.escape or encodeURIComponent.
How to disable irb's welcome banner or how to enable it for the Rails console
irb 1.18.0 adds a startup banner with version and hint information; it can be hidden or enabled in the Rails console through ~/.irbrc.
Capybara: Preventing server errors from failing your test
Capybara can fail tests after all steps when the Rails server raises an error on session cleanup. Filtering known missing-file errors avoids false failures.
Upgrade Rails: Awareness list
Awareness list for Rails upgrades with version-specific pitfalls and workflow references, including production logging changes in Rails 7 and 6.
How to inspect Rails view cache keys (when using Redis)
Rails view fragments cached in Redis are hard to inspect, but Rails.cache.redis.with(&:keys) can list existing keys. Production keyspaces may be very large.
Rails 3: Sending tempfiles for download
Temporary downloads can fail in Rails 3 when send_file triggers X-Sendfile and the web server cannot read files under /tmp. Using an allowed temp directory avoids 404 errors.
Checklist: Rails Authentication
Authentication is easy to get wrong because most users only sign in once. HTTPS with HSTS and a proven solution like Devise, Clearance or Rails primitives reduce security risks.
Collection of Rails development boosting frameworks
Rails app setup and admin scaffolding can speed up project bootstrapping, data management, and CRUD interfaces with templates and generators.
Rails: Adding a unique constraint for a has_one association might be a good default
A unique index on a has_one foreign key lets the database enforce 1:1 relationships and fail fast when application logic creates duplicate rows.