我使用的鐵軌2.3.8版本是有原因update_attributes方法不會觸發before_validation回調什麼特別的原因爲什麼update_attributes方法並沒有叫before_validation再打在我的模型
class x < ActiveRecord::Base
before_validation :testing
def testing
debugger
end
end
x.update_attributes(:名稱=> 「你好」)不會觸發before_validation
你的標題說'update_attributes',你的問題說'update_attribute'和'update_attributes',你的意思是?他們是截然不同的。 –
它只是x.update_attributes update_attribute的格式爲update_attribute(name,value)它是一個你應該通過參數格式理解的錯字錯誤 – suman
你的'testing'方法沒有運行,有什麼跡象?在你的例子中,該方法沒有body和IIRC,只有從回調中返回false纔會停止執行鏈,而不是nil。 –