Reputation: 11544
I’m using Datamapper (1.2.0) and Sinatra (1.3.2). I have a model and a property of the model is Employee ID. This is a mandatory field so whenever this is not been entered by the user I need to throw validation error.
Datamapper intelligently identifies the name of the property as 'Employee' (cuts down id part) and displays the error as 'Employee can't be blank' and 'Employee should be an integer'.
So I tried to override these error messages. I could able to override the 'Employee can't be blank' but cannot able to override the other.
property :employee_id, Integer, :required => true, :unique => true,
:messages => {
:presence => "Employee ID cannot be blank.",
:is_unique => "Employee ID should be unique."
}
What should be the hash key I need to use to override the 'not_an_integer' error?
Upvotes: 2
Views: 138
Reputation: 79723
I think the message key you’re looking for is :is_number
. Where this is documented is a bit hidden away. (I actually looked for it in the source).
Also, it seems to be if you have any :messages
hash in the property options then the default messages are replaced with nil
if you don’t specify a custom message for that validation.
Upvotes: 1