2011-10-11 54 views
1

我有before_update回調軌道3 before_update回調

def 
    if !condition 
    #not update record 
    end 
end 

的模型,我需要這個不是更新的東西,如何防止模型更新?

回答

1
self.errors.add(:base, "Some error message") 
return false 

我不認爲更新回調之前是一個很好的地方添加驗證碼。你可以用validates_each做同樣的事情。