after_create和after_save命令

时间:2011-05-12 18:14:00

标签: ruby-on-rails ruby-on-rails-3 activerecord

我做了一些测试,并且我发现after_create之前被调用而不是after_save(在Rails 2.3.9中)

这是对的吗?

感谢

2 个答案:

答案 0 :(得分:22)

是的,这是订单:

# (1) before_validation
# (2) before_validation_on_create
# (3) after_validation
# (4) after_validation_on_create
# (5) before_save
# (6) before_create
# (7) after_create
# (8) after_save 

在此处找到:

http://ar.rubyonrails.org/classes/ActiveRecord/Callbacks.html

答案 1 :(得分:0)

请记住,回调after_create只会执行一次。这是after_save和after_create之间的区别