3

Even if we add the most explaning error messages and make use of some good practices to do so, users simply don´t read error messages. One of the most recurring support that we have are errors already covered by validations not read by our users.

Our software has a control panel for the support people to have quick access to any usefull information they might need to provide a quick and quality support.

I want to add to this control panel a list of last validation errors per user so we can rapidly identify if the problem users are facing are just validation problems.

Are there any plugins that allow me to write a callback to any validation error in any model in my app?

I´d love to be able to write something like this

def on_any_validation_error(model, params)
  #my logic to add to some log control database backed or not    
end
Community
  • 1
  • 1
Ricardo Acras
  • 35,784
  • 16
  • 71
  • 112

1 Answers1

3

I don't know if a plugin like that exists but I've just played a bit with the after_validation callback, you could write an initializer with something like the following:

def log_errors
  log(self) unless errors.blank?
end
ActiveRecord::Base.send(:after_validation,:log_errors)

Then you have to implement your logic in the log method.

lucapette
  • 20,564
  • 6
  • 65
  • 59