Collecting failed validations

Hello,

Every now and then, I use a web app and it tells me that this or that field is invalid. Generally it’s an email address that doesn’t accept a plus before the @, or a phone number that doesn’t accept well formated international phone numbers (starting with a plus, containing hyphens) or maybe it fails to deal with my name or last name which contain this terrible characters: é and á. Of course, the developed failed here.

Generally I try to have my validations be much better about it, but I’m sure that I’m not inmune to the issue of rejecting valid data. What concerns me is that, unlike exceptions, for which I get an email, I’ll never know about this issues unless a user tells me, and they rarely do.

So, I was thinking, wouldn’t it be nice if Rails automatically saved the attributes of an object to the database when the validations fail? I suppose a gem could do it by monkey-patching validate or something like that and I’m also sure I’m not the first one to think of this.

Does anybody know if that gem already exists? If not, I’ll give it a try. What do you think about this feature? Does it sound useful?

Certainly a good idea. It is a source of frustration that otherwise remains hidden.

I would write this to the log with an INFO level and a special keyword, so I can collect the validation errors for analysis.

Peter

So, I was thinking, wouldn't it be nice if Rails automatically
saved the attributes of an object to the database when
the validations fail?

No, it wouldn't. Do you really want to have billions of records in your
database from all the spam bots trying to log in?

I never did this of course, but in similar situations, filtering bots wasn’t that hard. The filter was not perfect, but you don’t want perfect, you don’t need to catch every time someone puts valid information and is marked as invalid; you just need to get some of those, to improve the app.

If you don’t log or remove the entries for China and Russia and maybe some other countries, in my experience, you’ll get rid of most bots. Other filters could be, for example, invalid emails without an @ I don’t care about, but invalid ones with an @ I do care about.

You may want to have a captcha in your form anyway.

In most applications I built, the only public part is the register/login. Fine, I don’t log those. But the complex forms inside that my customers use constantly, I do want to know whether they are friendly or not.

I see the problem you point to, but I don’t think it’s a showstopper.

Well, then how about:

if not user.valid?
  logger.info user.errors.full_messages
end

http://addons.heroku.com/tripwire

"… Have you ever filled out a form only to have it rejected because of an unexpected, overly-restrictive validation error? It’s frustrating and annoying, and it probably happens to your users too.

Tripwire shows you the validation errors your users are experiencing, giving you a new way to uncover UX issues in your app. …"

Seems pretty much what you asked for.

Peter

Indeed it does. I don’t get it why it’s a Heroku addon and not just a simple plain gem.