2

I am seeding a test database in Rails 3.1 through thousands of create calls in the seeds.rb file.

A little problem arises when these calls do not pass the model validations: rails will not notify me this, and the seeding goes on correctly until the end of the file. At the end of the process I do not know which records have been created and which aren't, unless I check them one by one ...

Is there a way to get notified when records do not pass validations when using rake db:seed or rake db:reset?

Thank you!

1 Answer 1

2

You can create validations you want in the Models and use ModelName.create!. This will raise an exception if the input is invalid

Check this out http://apidock.com/rails/ActiveRecord/Validations/ClassMethods/create!

Hope this helps :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this. Just a note for others, I searched my seed file for .create( and replaced with .create!( and quickly found my validation issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.