LoginSignup
3
3

More than 5 years have passed since last update.

after_commit内ではchangesが空になってるので注意

Last updated at Posted at 2012-10-26
require "active_record"
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
  create_table :users do |t|
  end
end
class User < ActiveRecord::Base
  after_save do
    changes                     # => {"id"=>[nil, 1]}
  end
  after_commit do
    changes                     # => {}
  end
end
User.create!

ちょいとハマりました。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3