Rails has introduced this throw(:abort)
syntax, but now how do I get meaningful destroy errors ?
For validation errors one would do
if not user.save
# => user.errors has information
if not user.destroy
# => user.errors is empty
Here is my model
class User
before_destroy :destroy_validation,
if: :some_reason
private
def destroy_validation
throw(:abort) if some_condition
end
has_many
collection, - there is no error message created:post.comments.destroy(comment)
will raise no errors (at least in Rails console) but thecomment
element will not be destroyed in this case. It is supposed that you have aPost
model to havehas_many
comments relation and you havebefore_destroy
callback defined in Post model just before thehas_many
relation declared. – Headgear