Avoid duplicate entries created with seeds.rb?
I have the following code in mine seeds.rb
to create an entry in my simple Rails application.
Post.create(
title: "Unique Title!",
body: "this is the most amazingly unique post body ever!"
)
When running the command rake db:seed
, obviously the db seeds with this data. How to add validation or protection to the code so that it is included only once, i.e. How unique? If I restart rake db:seed
, I don't want to add this same entry again.
+3
source to share
3 answers