Returning an empty ActiveRecord scope
none returns an empty ActiveRecord::Relation for default objects and other cases where no records should match, with a fallback initializer for older Rails versions.
Rails: Testing the number of database queries
N+1 queries and excessive eager loading can be caught by asserting exact database query counts in specs with the make_database_queries RSpec matcher.
Make Less interpret the escape codes in a logfile
less can leave Rails logfile escape sequences unreadable; less -R preserves ANSI colors and other control codes while browsing logs.
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 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Upgrading Cucumber and Capybara to the latest versions available for Rails 2
Rails 2-compatible versions of Cucumber, Capybara, and related gems avoid breakage from newer dependencies and Capybara API changes.
Use SSL for Amazon RDS / MySQL (and your Rails app)
Encrypted connections between Rails and Amazon RDS MySQL protect sensitive data in transit. mysql and database.yml can be configured to require SSL end to end.
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.
How to avoid ActiveRecord::EnvironmentMismatchError on "rails db:drop"
Rails database tasks can fail with ActiveRecord::EnvironmentMismatchError after restoring a dump from another environment. Updating ar_internal_metadata or disabling the environment check lets rails db:drop proceed.