rails/rails — Issue #4852: after_initialize callback now called after a create block in 3.2
Author: chris-baynes
Created: 2012-02-02 15:06:20+00:00
State: open

In rails 3.1 a block passed to a model's #create method is yielded after the model is initialized:
https://github.com/rails/rails/blob/3-1-stable/activerecord/lib/active_record/base.rb#L509

In rails 3.2 a block passed to create will be passed on to #new, and subsequently yielded before the model after_initialize callback:
https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/persistence.rb#L44

I'm not sure I understand the reasoning for the change in rails 3.2.
Is there some other way to:

#rails 3.1
User.create(attrs) do |user|
# some code relying on a properly initialized user
# ...
end

than this:

#rails 3.2
user = User.new(attrs)
# some code relying on a properly initialized user
# ...
user.save