You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
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)."
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 message
b)
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.
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.
Created by lwouis - 2010-09-18 16:45:35 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1415
The text was updated successfully, but these errors were encountered: