2
Rails已經引入了這個throw(:abort)
語法,但現在我該如何獲得有意義的銷燬錯誤?Rails 5拋出異常:我如何設置錯誤信息?
驗證錯誤一個會做
if not user.save
# => user.errors has information
if not user.destroy
# => user.errors is empty
這裏是我的模型
class User
before_destroy :destroy_validation,
if: :some_reason
private
def destroy_validation
throw(:abort) if some_condition
end