How can I have Active Record warn and also report errors?

#1

Hi railers,

Is there a simple method to extend Active Record to have the same
functionality as the validate functions e.g.

validate_on_find
validates_acceptance_of
validates_each
validates_format_of
validates_length_of
validates_uniqueness_of

but report soft errors maybe to an object warn() instead of errors().
maybe
functions like:

warn_on_find
warn_acceptance_of
warn_each
warn_format_of
warn_length_of
warn_uniqueness_of

I am aware of save_with_validation(perform_validation = false) but we
want
to prevent saves if the model is invalid, these are just some softer
messages which we would like to retrive on find or save.

Any help will be greatly appreciated.

regards,
Leon

#2

One could achieve this my looking at
ActiveRecord::Validations::ClassMethods
and ActiveRecord::Validations in
vendor/rails/activerecord/lib/active_record/validations.rbhttp://api.rubyonrails.org/files/vendor/rails/activerecord/lib/active_record/validations_rb.htmlbut
is just does feel like the DRY method…

Any other suggestions?

#3

rewriting a module like ActiveRecord:Validations does not seem to be the
DRY
(Don’t Repeat Yourself) method. Is there any other method to have
warnings
on a model?