How DECIMAL columns deal with numbers exceeding their precision or scale

DECIMAL overflow and rounding differ by database: some systems reject out-of-range values, while others clamp or round to the nearest representable number.

Canceling event propagation

Event propagation can be stopped in different ways, with distinct effects on default actions, bubbling, and handlers on the same element. jQuery’s return false combines prevention and propagation stop.

ActiveRecord: Creating many records works faster in a transaction

Bulk inserts into one table can be much faster inside a transaction; Rails 6+ also offers insert_all for a single multi-row INSERT without validations.

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.

Testing if two date ranges overlap in Ruby or Rails

Date and time interval checks are easy to get wrong because partial, nested, and touching ranges all count as overlaps. A simple inclusive comparison works for Ruby and Rails.

How to define constants with traits

Traits can leak constant values across including classes when constants are assigned inside as_trait; binding them to self keeps each class’s constant separate.

Copying validation errors from one attribute to another

Virtual attributes can need validation messages shown on a different field, especially with Paperclip attachments and related file-name checks.

Know your Haml comments

Haml supports HTML comments that reach the browser and Ruby comments that stay server-side, with indentation errors causing confusing syntax failures.

Load order of the environment

Rails environment code loads in a fixed boot order, affecting which settings and constants can override others. Knowing the initialization sequence prevents surprises when adding configuration or app code.

Rails: Preloading associations in loaded records

Preloading nested associations on already loaded ActiveRecord objects avoids extra queries when rendering deeply related data and fits legacy Rails models via preload_associations.

Use the Git stash without shooting yourself in the foot

git stash apply leaves entries in place, so later stashing can restore the wrong changes; git stash pop applies and removes the top stash entry.