Rails: Default HTTP status codes when redirecting

Redirects in Rails use different default status codes in controllers and routes, and an unintended permanent redirect can affect browser behavior.

MySQL: Disable query cache for database profiling

MySQL query caching hides true database timings during profiling; disabling it and Rails per-request caching reveals actual query costs.

How to turn images into inline attachments in emails

External images in emails can fail in some clients; inline attachments with Rails and attachments.inline keep images visible, but turn messages into multipart emails and use content IDs.

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: 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: 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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.