Fixing wall of net/protocol warnings
Rails boot warnings from duplicate net-protocol constants after upgrading can be silenced by avoiding automatic loading of net-http, net-imap, net-protocol, and net-smtp.
Rails 4 introduced collection_check_boxes
Rails 4.0 adds collection_check_boxes for rendering checkbox groups from a collection and handling multi-value form params safely.
Adding Jasmine JavaScript specs to a Webpack(er) project
Browser-based unit tests in a Rails app can run with Jasmine and Webpacker by separating test runner and spec packs; a /jasmine page makes the setup easy to open.
Association to polymorphic model does not determine inverse_of automatically
Nested polymorphic associations can fail to save because Rails does not infer the inverse automatically; setting :inverse_of on the parent relation fixes the validation error.
Vortrag: Elasticsearch Grundlagen und Rails-Integration mit searchkick
Elasticsearch liefert Volltextsuche, Mappings, Shards und Aggregationen per REST-API; in Rails übernimmt searchkick Indizierung, Reindexing und Suchabfragen.
Migration from the Asset Pipeline to Webpacker
Moving a Rails app from the Asset Pipeline to Webpacker requires inventorying bundled libraries, repackaging legacy assets, and adjusting deployment for pack-based assets.
RSpec: How to test the content of a flash message in a request spec
Rails request specs can verify flash messages in the response, letting controller updates surface user feedback such as success or alert notices.
How to capture changes in after_commit
after_commit callbacks lose access to unsaved change data when Rails clears dirty tracking at commit. Rails 5+ provides saved_change_to_attribute? and previous_changes for commit-time checks.
Headless Chrome: Changing the Accept-Language header is not possible
Headless Chrome on Ubuntu cannot reliably change Accept-Language through Selenium options; test code can override the header in Rails instead.
Josh McArthur: Fancy Postgres indexes with ActiveRecord
Case-insensitive address uniqueness in Rails needs a functional PostgreSQL index and custom model validation when built-in helpers do not support expression-based constraints.
Rails logs are not flushed automatically (in Rake tasks)
Production Rake tasks can lose Rails log output because the logger buffers lines and does not flush on exit. Rails.logger.flush or a task wrapper writes pending entries to disk.
Rails 3: Make "link_to :remote => true" replace HTML elements with jQuery
Rails 3 remote links can replace page content with returned HTML, restoring the Rails 2 link_to_remote update behavior through jQuery and rails-ujs.
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.
Manually requiring your application's models will lead to trouble
Manually requiring Rails models can load classes twice and trigger duplicate validations or other subtle test failures. Let Rails autoload models or require them by the same path Rails uses.
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.
Rails: Rest API post-mortem analysis
Rails API backends can be fast and easy to extend, but serializer maintenance, schema drift, documentation limits, and missing rate limits create real operational risks.
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.
Fix error: can’t find executable rails
Rails fails to start when the rails executable points at a missing or half-installed gem set, often after an RVM mismatch or interrupted install.
Dynamically uploading files to Rails with jQuery File Upload
Immediate multi-file image uploads in Rails with progress bars, previews, and cached attachments support a single gallery form and responsive UI.
Caching in Rails
Rails 2.3 caching can speed up pages and views, but stale output and missing authentication hooks make cache strategy and invalidation tricky.
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.
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.
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.
passenger problems with upgraded rails-app
Passenger may misdetect an upgraded Rails app as Rails 1/2 and fail to spawn it; a full Apache restart can load the new application settings correctly.