Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用ClassName.update跳过回调?_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 如何使用ClassName.update跳过回调?

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

我有一个模型“Person”,我正在通过以下方式进行更新:

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时,有什么方法可以使用它吗?