Mutuelinvestor
Mutuelinvestor

Reputation: 3548

How do I create a Validation Error Log

I have a rails 3 application that involves a lot of importing of CSV files from a third party into various rails models. I have developed some scripts to perform most of the heavy lifting and today I added a lot of validation to the models to make sure valid data is going into the models/tables.

I'd also like to do some logging of validation errors so I can stay on top of all of the data processing and catch and correct validation errors quickly. To that end, I have taken the following steps:

  1. I created a ValidationError model to store validation errors.
  2. I initially create an instance using new.
  3. Once the object is built, I use valid? method and an if conditional to determine if the object it valid. If the the object is valid, I simply save it. If the object isn't valid I create a validation error record.
  4. I use the errors method to populate my ValidationsError instance.
  5. Then I create the ValidationError.create(validation_hash[])
  6. I'll display the validationError model in my ActiveAdmin dashboard and send out an email when validation entries are created.

Question(s): Is my proposed approach to capturing validation error reasonable. Are there approaches that have been used by others that may be better/preferable to what I propose. Is anyone aware of any gems or built-in functionality that would accomplish what I'm trying to do.

Upvotes: 1

Views: 525

Answers (2)

James
James

Reputation: 774

have also a look at this :)

Importing CSV file into multiple models at one time

and rail_admin_import gem, maybe you can expand with above staging table approach.

Upvotes: 1

usha
usha

Reputation: 29369

Have a look at validation_rage gem. you might be able to use that gem to achieve what you want.

Upvotes: 1

Related Questions