
Custom messages append instead of override
Reported by lwouis | September 18th, 2010 @ 11:45 AM
When you declare a property twice, and specify a custom message the second time, it gets appended to the default English message, instead of replacing it.
# In the dm-tags gem
class Tag
property :name [...]
end
# In my user model
class Tag
property :name, String, :required => true, :unique => true, :length => 50,
:messages => { :length => "Le nom est trop long (50 caractères max)." }
end
# Result when validation fails (:name too long)
=> "Name must be at most 50 characters longLe nom est trop long (50 caractères max)."
Comments and changes to this ticket
-
Martin Gamsjaeger (snusnu) October 27th, 2010 @ 02:36 PM
- State changed from new to confirmed
I can confirm that the default behavior is to append to the array of messages for the given property. I have to explicitly say that it's actually not appending to a String tho, but it adds a new String to the array of error messages.
It seems like currently
dm-validations
keeps track of a single error messages array for every property. This is so that it's possible to add multiple error messages by defining multiple validations on the same property. However, it seems that there's currently no way to overwrite any previously defined error message, since all it does is append atm.I wonder if it's feasible to either
a)
make sure that every property option (like :length) can only have one associated error messageb)
keep an array for every property option, and append to that by making the error message a String, or overwrite it by giving an array?property :name, String, :messages => { :length => "blabla" } # append a new message property :name, String, :messages => { :length => ["blabla"] } # replace previous messages with this
In general, we should maybe also discuss what it means to "overwrite" a property? I'm not sure wether I'm leaning towards allowing to refine it vs. simply overwriting it.
What do you guys think?
-
-
Piotr Solnica (solnic) May 17th, 2011 @ 02:18 AM
- Tag changed from message, model, property, validation to dm-validations, message, model, property
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »