Skip to content

Instantly share code, notes, and snippets.

@mlarraz
Last active June 4, 2016 01:02
Show Gist options
  • Save mlarraz/b7346aa6ea048ea4df04bda5175c5f18 to your computer and use it in GitHub Desktop.
Save mlarraz/b7346aa6ea048ea4df04bda5175c5f18 to your computer and use it in GitHub Desktop.
Using previous_changes in an after_commit hook
class AddFoos < ActiveRecord::Migration
def change
create_table :foos do |t|
t.string :bar
end
end
end
class Foo < ActiveRecord::Base
after_commit do
puts previous_changes
end
end
Foo.create!(bar: 'baz')
# => {"bar"=>[nil, "baz"], "id"=>[nil, 1]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment