Ah!
I just overrode DM::V::ValidationErrors.default_error_messages
somewhere after the gem is loaded, but before models are. In Rails 3,
this means creating an initializer and placing http://gist.github.com/447681
in it. Total monkey patch, but it works.
As for custom validation, you'd most likely want to create a validator
class that inherits from DM::V::GenericValidator. The catch with:
if u.valid?
u.errors.add(:name, 'Invalid name')
puts "Valid: #{u.valid?}"
end
is that calling #valid? actually clears all errors, then reruns all
validators for that resource.
However, if you only want to override the default validation error
messages, might I suggest another ugly hack: http://gist.github.com/447683
.
-rp
On Jun 21, 2010, at 6:18 PM, Dan Sosedov wrote:
Yeah, i saw the default messages, but i dont really want to change
original gem.
Also, i noticed that custom validation errors does not work.
Example:
class User
include DataMapper::Resource
property :id, Serial
property :name, String
property :email, String, :length => 6..64, :format
=> :email_address
end
u = User.new(:name => 'My name', :email => '[email protected]')
if u.valid?
u.errors.add(:name, 'Invalid name')
puts "Valid: #{u.valid?}"
end
Or maybe im just doing it wrong. Ideas?
On Jun 21, 9:13 am, Ripta Pasay <[email protected]> wrote:
AFAIK, there isn't an option to disable column names from being
included.
Instead, I do what you describe: change the default validation
messages
(DataMapper::Validations::ValidationErrors.default_error_messages=).
Unfortunately, this also means I had to monkey-patch
DM::V::VE.default_error_message so that it doesn't interpolate the
field name.
-Ripta
On Jun 16, 8:47 pm, Dan Sosedov <[email protected]> wrote:
Oh, and i forgot to add, this can be done with custom validation
messages.
But the question still the same: is it possible to make this
conversions automatically?
--
You received this message because you are subscribed to the Google
Groups "DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected]
.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en
.
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.