[フレーム]
Last Updated: February 25, 2016
·
1.165K
· 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
end

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 ·

AltStyle によって変換されたページ (->オリジナル) /