Rails: Comparison of Dates - before? and after?

Rails 6+ adds before? and after? for comparing dates and times; between? checks whether a value falls within a range.

Rails: How to find records with empty associations

Find Rails records with no associated rows, such as decks without cards or cards without a deck, using where.missing or left_joins.

Five years of "Today I Learned" from Josh Branchaud

A curated set of 900+ personal programming tips spans Ruby, Rails, Git, Unix, Chrome, and JavaScript, with many small shortcuts for daily development work.

Rails: Migration helper for inserting records without using models

Safer migration data seeding without loading application models, using a small SQL wrapper for direct row insertion with timestamps.

Apply a new callback to existing records

Run a newly added model callback for existing production records without replaying validations and unrelated callbacks; suitable for backfilling cached data after deployment.

Rails: Kill spring with fire

Rails Spring processes can linger and restart unexpectedly, interfering with command runs; stopping the process and disabling auto-start prevents it from coming back.

Rails: render a template that accepts a block by using the layout option of render

Reuse a form partial with a customizable submit section by rendering it as a layout and yielding the form object into a block.

Setting expiry dates for images, JavaScript and CSS

Static asset caching in Rails can be unreliable across browsers; setting expiry headers in Apache or Nginx improves delivery of images, JavaScript and CSS.

Rails: Removing the cucumber-rails warning when setting cache_classes to false without Spring enabled

cucumber-rails emits a transaction warning in test runs when cache_classes stays false without Spring, affecting parallel execution setups.

Debug MiniMagick calls in your Rails app

CarrierWave hides MiniMagick processing failures behind a generic error; enabling MiniMagick.logger.level = Logger::DEBUG reveals the underlying ImageMagick commands and helps trace the cause.

Reading the Rails session hash from a Rack middleware

Accessing Rails session data inside Rack middleware is possible through env['rack.session'], which provides an ActionDispatch::Request::Session object.

How to fix: irb / rails console randomly crashing

irb and rails console can crash unpredictably because of multi-line autocomplete; disabling it may stop the failures.

A non-weird replacement for grouped_collection_select

Rails grouped select helper feels awkward; flat_grouped_collection_select groups arbitrary collections by a field for simpler select menus.

Managing vendor libraries with the Rails asset pipeline

Rails asset pipeline issues make vendor libraries hard to keep separate; custom asset paths and rewritten font URLs preserve clean library folders and correct references.

Security issues with hash conditions in Rails 2 and Rails 3

Hash conditions in Rails scopes can overwrite earlier constraints when chained, creating security risks in user-filtered queries. SQL fragments avoid the overwrite, but change record-building behavior.

How to use Active Job to decouple your background processing from a gem

Background jobs in Rails can stay adapter-agnostic by using ActiveJob, making Sidekiq or Resque easy to swap without changing worker code.

Ruby on Rails: Finding a memory leak

Memory leaks in Ruby on Rails can be hard to isolate. rbtrace, ObjectSpace.trace_object_allocations_start, heapy, and sheap help trace allocations and narrow down the source.

Yarn: if integrity check won't let you start rails console

Yarn integrity warnings can block rails console even when packages are current; stale Spring cache may keep the error until spring stop clears it.

A short overview of common design patterns implemented within Rails

Rails code patterns help communicate refactor requests, improve code reviews, and introduce reusable approaches such as service objects, presenters, and query objects.

Persist Rails or IRB Console Command History After Exit

Keep Rails or IRB commands available after exit by saving console history to a file and increasing the retained history length.

Use DatabaseCleaner with multiple test databases

Rails apps with multiple databases need separate test cleanup, or records bleed between specs and migrations. DatabaseCleaner can target each connection via a model-backed database key.

Returning an empty ActiveRecord scope

none returns an empty ActiveRecord::Relation for default objects and other cases where no records should match, with a fallback initializer for older Rails versions.

Rails: Testing the number of database queries

N+1 queries and excessive eager loading can be caught by asserting exact database query counts in specs with the make_database_queries RSpec matcher.

Make Less interpret the escape codes in a logfile

less can leave Rails logfile escape sequences unreadable; less -R preserves ANSI colors and other control codes while browsing logs.