Preloaded associations are filtered by conditions on the same table
When you eagerly load an association list using the .include option, and at the same time have a .where on...
Copying validation errors from one attribute to another
When using virtual attributes, the attached trait can be useful to automatically copy errors from one attribute to another.
Collect all values for a given column in an ActiveRecord scope
In modern Rails versions you can also use ActiveRecord's pluck method. >> User.active.pluck(:id) => [1, 5, 23, 42]
Know your Haml comments
There are two distinct ways of commenting Haml markup: HTML and Ruby. HTML comments This will create an HTML comment...
Load order of the environment
Rails 3, 4, 5, 6 config/application.rb config/environment.rb before the initialize! call (we don't usually edit this file)
Preload associations in loaded records
Sometimes you want to fetch associations for an ActiveRecord that you already loaded, e.g. when it has deeply nested associations...
Efficiently add an event listener to many elements
When you need to add a event listener to hundreds of elements, this might slow down the browser. An alternative...