DataMapper models allow custom validations of two forms: those specific to a property, and overall object validations. For example:
# Validates the `name` property with the `check_name` method;
# any errors will be under `object.errors[:name]`
validates_with_method :name, method: :check_name
# Validates the object overall with the `overall_soundness` method;
# any errors will be under `object.errors[:overall_soundness]`
validates_with_method :overall_soundness
The second type makes sense for validations that involve multiple properties, but it also presents a problem: displaying errors to the user.
I'd like to display all errors that aren't attached to a particular property at the top of the form's page, but I don't see any easy way to list them.
How can I get a list of non-property-specific errors?
(I'm using DataMapper 1.2.0)
A hacky way
I'm hoping there's a more native way than this. I've added this method to my model:
At the top of a form, I can do this:
Or, a monkey patch to Formtastic to allow
f.general_validation_errors
would be: