Center a float horizontally

Centering a floated element can fit content width when inline-block is unavailable. A CSS/SASS wrapper and Rails helper provide IE7+ support.

Switching the package manager from yarn to npm

Migrating a Rails app from yarn to npm can reduce dependency complexity and avoids upgrading to Yarn 2.0. Matching package versions helps keep installs stable.

whenever: Installing cron jobs only for a given Rails environment or Capistrano stage

Conditional cron jobs in whenever can target only one Rails environment or Capistrano stage, avoiding unwanted tasks on other deployments.

Howto respond html or json in the same controller action with Rails 2

Rails 2.3 can return either HTML or JSON from one controller action, but render_to_string inside format.json may trigger ActionView::MissingTemplate.

Rails: Rescuing exceptions for specific exception types

Rails can map selected exceptions to non-500 responses and suppress error monitoring noise, such as returning 404 for missing records or denied access.

Using the ActiveSupport::BroadcastLogger

ActiveSupport::BroadcastLogger sends one log message to multiple outputs, useful for writing Rails and Sidekiq logs to both STDOUT and files.

Difference between respond_to/format and params[:format]

Non-HTML Rails responses can differ from params[:format]; respond_to also matches MIME negotiation, so authorization should not depend on a URL suffix alone.

How to kill a Rails development server by force

A stuck Rails development server can keep port 3000 busy and trigger EADDRINUSE; lsof and kill -9 can force it down.

What edge_rider offers you

ActiveRecord relation helpers reduce object instantiation, simplify association traversal and preloading, and bridge Rails version differences with a unified API.

Rails: Custom validator for "only one of these" (XOR) presence validation

Rails models often need exactly one of several attributes filled in; built-in validations do not handle this XOR case cleanly. A custom ActiveModel::Validator can enforce blank-or-singleton presence with clear errors.

Rails: When defining scopes with class methods, don't use `self`

Scopes defined as class methods can drop earlier filters when they return self; use all to preserve chained conditions in Rails 2 and 5.

Middleman configuration for Rails Developers

Rails-friendly Middleman setup for live reload, asset pipeline, i18n, environment-specific config, browser testing, and Capistrano deployment.

CarrierWave: How to remove GIF animation

Animated GIF uploads can slow Rails workers and waste processing time; dropping all but the first frame with ImageMagick avoids resizing work.

Rails: Validations of Dates, Numerics and Strings with ComparisonValidator

Rails 7+ validates dates, numbers and strings with ComparisonValidator for greater-than and less-than checks, replacing custom comparison code.

Simple database lock for MySQL

MySQL can coordinate multiple Rails processes with a database-backed mutex when code must not run concurrently. It is for model-level synchronization, not record locking.

Configuring Webpacker deployments with Capistrano

Rails deployments with Webpacker and Capistrano often need asset-path, manifest, and compile-time tweaks to avoid slow releases and unused compression output.

Collect all values for a given column in an ActiveRecord scope

Retrieve all values from one ActiveRecord column without instantiating records; pluck, ids, and distinct return arrays efficiently, with collect_column for older Rails.

Rails: How to test the parsed response body

Rails response tests can parse bodies by MIME type with parsed_body, replacing manual JSON.parse(response.body) in many cases and enabling cleaner assertions.

An incomplete guide to migrate a Rails application from paperclip to carrierwave

Rails file storage migration with background jobs, reruns, and URL rewrites; large media backfills need careful testing, queue tuning, and fallback handling.

Rails asset pipeline: Why relative paths can work in development, but break in production

Relative asset URLs can work in Rails development but break after assets:precompile, because files are merged into public/assets and fingerprinted.

Rails SQL Injection Examples

Unsafe ActiveRecord query methods can expose applications to SQL injection when raw SQL is built from untrusted input.

Bash: How to grep logs for a pattern and expand it to the full request

Find all Rails log lines for matching requests by extracting request IDs and re-grepping the full log, avoiding interwoven output from concurrent requests.

Using PostgreSQL ranges with ActiveRecord

PostgreSQL range types store date and time intervals in one column and fit ActiveRecord casting, overlap queries, and exclusion constraints for booking data.

Specify Gemfile for bundle

BUNDLE_GEMFILE selects a nondefault Gemfile for Bundler, making it possible to work with multiple Gemfiles in one project and test against different Rails versions.