Last active
June 4, 2016 01:02
-
-
Save mlarraz/b7346aa6ea048ea4df04bda5175c5f18 to your computer and use it in GitHub Desktop.
Using previous_changes in an after_commit hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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