Skip to content

Instantly share code, notes, and snippets.

# This is a workaround for the Rails issue described in
# https://github.com/rails/rails/issues/17368.
#
# When assigning `_ids=` on a has_many :through association, Rails immediately
# persists the changes to the join table — even before `save` is called. This
# module defers that persistence to an `after_save` callback, so the IDs are
# only written when the parent record is saved.
#
# If you use this, make sure you understand its code and what it does and what
# it doesn't.
@xaviershay
xaviershay / migration_sql.rb
Created August 14, 2015 21:21
Get SQL output from a Rails migration
#!/usr/bin/env ruby
require_relative 'config/environment'
path = ARGV.shift || raise("specify migration as first argument")
require_relative path
filename = File.basename(path, ".rb")
timestamp, name = filename.split("_", 2)
@chetan
chetan / yardoc_cheatsheet.md
Last active April 2, 2026 16:49
YARD cheatsheet
@eirc
eirc / .rvmrc
Created October 20, 2011 07:53 — forked from jimeh/decode.rb
Ruby-based Benchmark of MessagePack vs. JSON vs. Yajl vs. Protobuffers vs. MultiJson vs. Marshal vs. YAML vs. BSON
rvm --create ree@benchmarks