WYSIWYG with Action Text
Rails 6 Action Text provides a built-in WYSIWYG editor for rich text fields, with Trix hooks for custom toolbar buttons and attachment handling.
Local development with SSL and Puma
Local HTTPS for Puma development needs a trusted certificate and SSL binding so Rails runs on https://localhost:3000 without browser warnings.
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.
Rails: Remove Blank Values from Collections
Rails collections often retain empty strings, nil, whitespace, empty arrays, hashes, and false values; compact_blank removes them from arrays and hashes in Rails 6.1+.
How to use Rails URL helpers in any Ruby class
Accessing Rails path helpers from plain Ruby classes can be awkward, and including all route helpers risks method clashes. Delegating url_helpers exposes only the needed path methods.
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.
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.
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.
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.
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.
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: 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.
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.
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.
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.
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: 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.
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.
Rails SQL Injection Examples
Unsafe ActiveRecord query methods can expose applications to SQL injection when raw SQL is built from untrusted input.
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.
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.