class MyModel < ActiveRecord::Base
before_save :assign_foo
private
def assign_foo
self.foo = false
end
end
Hal tersebut akan menyebabkan callback gagal karena baris self.foo akan dievaluasi sebagai block oleh Ruby sehingga akan mengembalikan nilai false.
If a before_* callback returns false, all the later callbacks and the associated action are cancelled. If an after_* callback returns false, all the later callbacks are cancelled.Solusinya adalah pada baris terakhir atau setelah baris self.foo = false, tuliskan nil atau return.
class MyModel < ActiveRecord::Base
before_save :assign_foo
private
def assign_foo
self.foo = false
nil
end
end
0 comments:
Post a Comment