Rails已经引入了这种throw(:abort)语法,但现在我如何获得有意义的销毁错误?
对于验证错误,人们会这样做
if not user.save
# => user.errors has information
if not user.destroy
# => user.errors is empty
Run Code Online (Sandbox Code Playgroud)
这是我的模特
class User
before_destroy :destroy_validation,
if: :some_reason
private
def destroy_validation
throw(:abort) if some_condition
end
Run Code Online (Sandbox Code Playgroud)