Preventing delete of has_many children in Rails 3
If you’ve tried to use rails 3 validate on a destroy, you might notice that error messages which were set in the before_destroy don’t get passed back to the user.
It seems like many people out there have posted code that tries to tell you that you can set the record.errors in the model. Well, let me tell you that it doesn’t work for various reasons.
Here’s an example of a workaround I’m using where a building contains many rooms.
As you can see, an RecordInvalid is thrown from the model and caught in the controller. Then, in the controller, the flash is set to the error message.