ruby - ActiveRecord callback after_save not really called after saved -



ruby - ActiveRecord callback after_save not really called after saved -

having this:

class user < activerecord::base after_save :execute_after_save def execute_after_save kernel.puts "actual object still not saved" if changed? end end

the kernel.puts sentence should called never because after object saved not changed.

1.9.3p286 :003 > u = user.create!(:name => "wadus name") actual object still not saved => #<user id: 1, name: "wadus name"> 1.9.3p286 :004 > u.changed? => false 1.9.3p286 :004 > u.name = "other name" => "other name" 1.9.3p286 :005 > u.changed? => true 1.9.3p286 :006 > u.save! actual object still not saved => true 1.9.3p286 :007 > u.changed? => false

see actual object still not saved sentences shouldn't there.

i expecting after_save callback called after object saved.

this situation turning me crazy combinations of dirty objects , callbacks have do.

it's after save before commit.

after_commit might you're looking for.

ruby ruby-on-rails-3 activerecord callback

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -