We have deprecated Rack::SteadyETag
Rack::SteadyETag generated stable ETags for responses that only changed in CSRF tokens or CSP nonces. Rails apps should be configured to return identical HTML for the same resource and user.
RSpec: How to compare ISO 8601 time strings with milliseconds
Rails JSON serializes times with milliseconds, so iso8601 and to_json can differ in RSpec expectations. Using to_json keeps time string comparisons matching.
Save ActiveRecord models without callbacks or validations (in Rails 2 and Rails 3)
Persist ActiveRecord records directly when callbacks and validations are unnecessary; Rails 2 has create_without_callbacks and update_without_callbacks, while Rails 3 needs sneaky-save.
Downloading files from Ruby on Rails
Serving files as downloads in Ruby on Rails uses send_file; it returns the file directly and overrides the normal render response.
Beware of rails' reverse_order!
reverse_order breaks on complex SQL sorting and can generate invalid queries in Rails 4; Rails 5 raises ActiveRecord::IrreversibleOrderError instead.
Bundler for Rails 2.3.x
Bundler support for Rails 2.3.x requires updated RubyGems and Passenger, a bundled Gemfile workflow, and bundle exec for tests and deployment.
Why Sidekiq Jobs should never be enqueued in an `after_create` or `after_save` callback
Database transactions can roll back after after_save, leaving Sidekiq jobs queued for records that never persist. after_commit runs after persistence and avoids this race.
Sprites with Compass
CSS sprites can reduce image requests by bundling small backgrounds into one sprite; Compass and compass-rails automate sprite generation in Rails apps.
Accessing Rails config in webpack(er)
Rails secrets and other configuration values can be read inside webpack bundles with rails-erb-loader, enabling environment-specific client-side settings without hardcoding them.
Heads up: Byebug has problems with zeitwerk
Byebug 11.1.3 can trigger NameError with Rails 6 zeitwerk autoloading; binding.pry, eager loading, or another debugger avoid the issue.
Heads up! Years are always floats in Rails < 4
1.year returns a Float in Rails < 4 and can break code that expects an integer duration; Rails 4 uses ActiveSupport::Duration instead.
Managing vendor assets in Rails with Bower
Rails asset management becomes easier with bower-rails, using a Bowerfile and rake tasks to install, list, update, and rewrite vendored front-end packages.
Rails routes: Extracting collection actions into their own controllers
Rails routing can make singleton collection pages awkward to place under a namespace without adding :project_id; custom controller paths or namespace/resource combinations keep URLs and controllers aligned.
How to split config/routes.rb in Rails 4
Splitting Rails route definitions across multiple files can improve organization in larger apps. Rails::Engine and config.paths['config/routes.rb'] can load route files from config/routes/.
Rails: Parsing a time in a desired timezone
Create a Time in a fixed timezone regardless of Rails or system settings; useful for tests and API date comparisons when parsing otherwise shifts by environment.
Heads up: Rails offers two similar means for text truncation
Rails has both truncate helper and String#truncate; the helper is preferred for block support and safer HTML handling, especially with escape: false.
Running Rails 2 apps with modern MariaDB SQL server
Rails 2 apps can break on MySQL 5.7; MariaDB 10.x is a compatible replacement for old and new applications, with gem rebuilds sometimes needed after switching.
Fix for "Rails assets manifest file not found" in Capistrano deploy
Webpacker-only Rails deploys can fail on deploy:assets:backup_manifest because capistrano-rails expects Sprockets assets. Clearing that task avoids the missing manifest error.
Terminator setup for Procfile-based applications for more comfortable debugging
Terminator can split Rails debugging into separate panes, keeping the web server and other Procfile processes visible without mixed log output.
Rails: Send links in emails with the right protocol
ActionMailer defaults to http in email links, which can expose session cookies to SSL-stripping. Set default_url_options or the link protocol to use https where needed.
Rails: Use STI in Migration
ActiveRecord migrations can break when STI models are referenced directly; embedding model classes in the migration and overriding find_sti_class and sti_name keeps type lookup working.
Rails 2's CookieStore produces invalid cookie data, causing tests to break
Recent Rails 2 CookieStore versions can emit malformed Set-Cookie headers with blank lines, breaking Cucumber integration tests when cookies are written more than once.
Rails 3: Mass assignment protection and .create_with
create_with and where can bypass Rails 3 mass-assignment protection, allowing protected attributes to be set from untrusted input.
Structuring Rails applications: the Modular Monorepo Monolith
Monolithic Rails apps can stay maintainable by splitting code into a monorepo of Rails Engines and gems with explicit component dependencies.