Authorize allowed values with assignable_values
Restricting attribute values to user-dependent sets keeps select options and labels in sync while supporting defaults and authorization-aware assignment.
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.
Why two Ruby Time objects are not equal, although they appear to be
Time comparisons can fail in tests because Ruby keeps subsecond fractions even when the printed values look identical.
Don't name columns like counter_cache columns in Rails pre v4.2.4
Rails can mistake ordinary columns for cached association counters and return empty has_many collections when the cached value is wrong.
Ruby: You can nest regular expressions
Ruby can interpolate existing Regexp objects into new patterns, preserving modifiers like /i only inside the nested region.
routing-filter is broken with Rails 7.1
routing-filter stops working in Rails 7.1 because find_routes now yields lazily, leaving URL segment filters unapplied and routes unrecognized.
Active Record: Never use optional with a symbol, lambda or proc
Association options can silently skip presence checks when optional is given a symbol, lambda, or proc, allowing invalid records with missing related objects.
Bash script to list git commits by Linear ID
Bash helper for finding git commits by Linear issue ID, including IDs extracted from Linear URLs, and passing options through to git show.
Ruby: How to use global variables for a conditional debugger
Global variables can temporarily gate a Ruby debugger, avoiding repeated stops in callbacks and specs when only one execution path matters.
Heads up: Sidekiq per default silently fails when retries are exhausted!
Sidekiq retries can run out silently, leaving failed jobs only in the dead queue. Add explicit notification logic when permanent worker errors exhaust retries.
RSpec: Using helpers in view specs
View specs can crash on undefined helper methods; enabling config.action_controller.include_all_helpers or including helper modules makes view rendering work.
Rails: Integrating shoelace components
Web components from Shoelace can be integrated into a Rails app with webpack and Unpoly, offering an alternative setup to the official approach.
Capybara: Quick checking for element presence (without retries or timeout)
Capybara presence checks can wait for seconds or raise on find; has_css? with wait: 0 returns immediately for quick boolean checks.
Nested ActiveRecord transaction pitfalls
Nested ActiveRecord transactions can hide inner ActiveRecord::Rollback exceptions or fire after_commit callbacks too early, depending on joinable: false and requires_new.
Capybara: Find an element that contains a string
Capybara can locate DOM nodes by text content using text: with a selector or regular expression, avoiding unsupported CSS string-matching selectors.
Always convert and strip user-provided images to sRGB
User-uploaded images can lose correct colors if metadata is stripped before color conversion. Converting to sRGB and reattaching the profile keeps browser rendering consistent.
Ruby: How to determine the absolute path relative to a file
Use File.expand_path with __dir__ or __FILE__ to build file paths that stay correct regardless of the caller’s working directory.
Using ngrok for exposing your development server to the internet
Temporary public access to a localhost development server is useful for testing on another device or through TLS without port forwarding or self-signed certificates.
makandra cards: A knowledge base on web development, RoR, and DevOps
Internal knowledge base with best practices for web development, Ruby on Rails, DevOps, and trainee programs, used by developers worldwide to find practical solutions and learning paths.
Rails: Using require and permit for attributes
Stricter strong parameters raise missing and unpermitted attribute errors during development and tests, helping catch bad requests earlier while requiring environment-specific handling in production.
Unpoly + Nested attributes in Rails: A short overview of different approaches
Rails nested attributes become cumbersome with dynamic subrecords; Unpoly enables friendlier add/remove workflows without losing server-side validation and form helpers.
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.
Testing ActiveRecord callbacks with RSpec
Database-backed RSpec checks for ActiveRecord lifecycle behavior are more reliable than stubs when verifying side effects like automatically creating associated records.
Bookmarklet to generate a commit message for an issue in Linear.app
Issue-linked commit messages need a ticket ID prefix; a bookmarklet can prefill the correct [ID] title format from a Linear issue view.