Last Updated: February 25, 2016
· kalashnikovisme

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

2 Responses
Add your response

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 ·

As you wish :)

over 1 year ago ·