Ruby on rails 如何使用ClassName.update跳过回调?
我有一个模型“Person”,我正在通过以下方式进行更新:Ruby on rails 如何使用ClassName.update跳过回调?,ruby-on-rails,ruby,Ruby On Rails,Ruby,我有一个模型“Person”,我正在通过以下方式进行更新: hash = {"id" => 1} updatedHash = {"name" => "UPDATED_NAME"} Person.update(hash["id"], updatedHash) 在我的个人模型中,当其更新时,我有一个回调: after_commit :postUpdate, :on => :update after_update :postUpdate #optionally I can hav
hash = {"id" => 1}
updatedHash = {"name" => "UPDATED_NAME"}
Person.update(hash["id"], updatedHash)
在我的个人模型中,当其更新时,我有一个回调:
after_commit :postUpdate, :on => :update
after_update :postUpdate #optionally I can have this, and exclude the above
如果使用Person.update,如何停用此回调?(不要告诉我使用update_column或任何这些方法,因为我无法更改更新的方式)
我试过:
Person.skip_callback(:update, :after_commit)
但是它不起作用我相信你需要这样做
Person.skip_callback(:update, :after_commit, :postUpdate)
或者调用要跳过的回调的任何名称
作为旁注。在ruby中,对变量和函数名使用snake case而不是camel case是合适的。当回调被分配为lambda时,有什么方法可以使用它吗?