The best solution I have right is like doing writing it like below.
Before release of production
if Category.count == 0
categories = Category.create([{ name: 'business' }, { name: 'sport' })
end
After
if Category.count == 0
categories = Category.create([{ name: 'business' }, { name: 'sport' })
elsif Category.count == 2
Category.create([{ name: 'science' }])
categories = Category.all
end
This is kinda fail since I have to write [{ name: 'hoge' }] everytime I add a data.
And I might miss count the Category.count === COUNT which is in the elsif block.
Any better solution?
I think it’ll be nice if its able to add/remove some value from a certain Array to update the master data.
Use find_or_create with an array of data:
Edit: sorry, that was the syntax in Rails 4…