running rake db:seed without duplicating data
Use find _ or _ create_by method
nomination_titles = [
'Репортаж',
'Новость',
'Статья',
'Интервью',
'Обзор'
]
nomination_titles.each do |title|
Nomination.find_or_create_by_title title
end
Written by Павел Калашников
Related protips
2 Responses
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/95856/2c4ac578c73a0b876f3ffe997e6a8541.jpeg)
I tend to use Nomination.where({ title: title, another: attribute}).first_or_create
This allows for finding by multiple attributes and looks a little cleaner too in my opinion
over 1 year ago
·
![](https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/75545/d46b07735d3a304d9eb5dfac8f359ea6.jpeg)
As you wish :)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#