Rails: How to stub the env in Rails 7+
Rails 7.1 adds Rails.env.local?; stubbing Rails.env with a plain string can fail, while ActiveSupport::EnvironmentInquirer keeps environment checks working.
A simple example with a GIN index in Rails for optimizing a ILIKE query
ILIKE searches in PostgreSQL can be slow without trigram indexing; a GIN index with pg_trgm can replace sequential scans with bitmap index scans.
RSpec: Example groups define constants that can shadow your models
RSpec example groups can define constants that shadow Rails models during association class lookup, causing flaky failures when spec files load in the same process.
A simpler default controller implementation
Rails controllers can stay short, testable and authorization-friendly by using a minimal shared blueprint for CRUD, strong params, scopes and optional HTTP caching.
How to accept more than 4k query parameters in Rails
Large form submissions can fail with hidden Rack::QueryParser::QueryLimitError when total request parameters exceed Rails' default limit. Raising params_limit allows bigger POSTs.
tel_to Rails helper for linking phone numbers
tel: links let smartphone users call phone numbers from web pages, and a small Rails helper turns human-readable numbers into clean clickable dial links.
Livereload + esbuild
Live CSS and JS reloading in Rails with esbuild is awkward because generated assets change on every build. A guard-livereload plus livereload-js setup can avoid full-page reloads for stylesheet changes.
Searchkick: async reindexing fails for rails 7 with redis 4
Searchkick async reindexing can break on Rails 7.1 with Redis 4 because ActiveSupport#with conflicts with the Redis API, causing undefined method 'call' for nil.
How to test a controller concern with rspec-rails anonymous controllers
RSpec controller concerns can be exercised with anonymous controllers, letting shared authorization behavior be tested through real requests without messy dummy routes or rebuilt stacks.
Rails: Comparison of assignable_values and Active Record enum types
Rails enum attributes store states as integers or database enums, with validation and generated scopes; assignable_values still offers conditional rules, associations, and array support.
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.
Carrierwave: How to remove container directories when deleting a record
Deleting uploaded files in Rails leaves empty CarrierWave folders behind; a cleanup hook can remove empty parent directories after record deletion.
request_store: Per-request global storage for your Rails app
Per-request storage for Rails avoids leaking state between requests when using Thread.current; middleware clears data automatically at request end.
How to update the bundler version in a Gemfile.lock
Bundler versions in Gemfile.lock can lag behind the installed release and break compatibility with older Ruby or Rails setups. Updating bundler and regenerating the lockfile keeps BUNDLED WITH aligned.
Fuzzy scoping in Rails with PostgreSQL
Approximate string filtering in Rails can find names that nearly match a term by using PostgreSQL trigram similarity and a tunable threshold.
Rails: Flagging all cookies as secure-only to pass a security audit
Secure cookies are often required by audits even when a Rails app already uses HTTPS and HSTS. A middleware can add the Secure flag to server-set cookies automatically.
ActiveSupport includes Timecop-like helpers
Rails test helpers let you freeze or shift time without Timecop; travel_to, travel, and freeze_time simplify time-dependent specs when clock progression does not matter.
Don't mix Array#join and String#html_safe
Mixing safe and unsafe HTML strings with Array#join breaks Rails output safety and can trigger incorrect escaping or unsafe rendering.
Heads up: Quering array columns only matches equally sorted arrays
PostgreSQL array queries in Rails match element order, so [16, 17] and [17, 16] are different. Order-independent matching needs normalization or bidirectional containment.
Unpoly: Passing Data to Compilers
Rails data can be passed to Unpoly compilers through data-* for simple strings and up-data for objects, arrays, and nested values.
Rails: Preparing scopes with values for creation
where, default_scope, and create_with control which attributes relations apply to new records and how default query conditions differ from default creation values.
Stabilize integrations tests with flakiness introduced by Turbo / Stimulus / Hotwire
Turbo-driven Rails integration tests can become flaky under load because asynchronous renders and requests finish unpredictably. A Stimulus-based lockstep controller coordinates Capybara with Turbo events.
High-level data types with "composed_of"
Rails composed_of bundles several columns into one value object, but immutability, validation, caching, and form handling remain fragile.
Devise: Invalidating all sessions for a user
Stolen Rails session cookies can remain usable after logout with Devise. Invalidating them requires changing the authentication salt, resetting the password, or storing sessions server-side.