Rieles Reiniciar seed.rb

I've created a dropdown menu database of categories in my seeds.rb file and accidentally did rake db:seed another time to add duplicate categories. Being a noob, I'd like to know what's the best way in a development ENV to make the category dropdown reset and put back the following categories...

Seeds.rb

Category.create(name: 'General')
Category.create(name: 'Birthday')
Category.create(name: 'Sports and Recreation')
Category.create(name: 'Music')
Category.create(name: 'Nature')
Category.create(name: 'Education')
Category.create(name: 'Political')

preguntado el 24 de agosto de 12 a las 05:08

2 Respuestas

You can prepend your seeds.rb file with Category.destroy_all. This will instantiate and destroy all your categories.

Respondido 24 ago 12, 06:08

If you didn't want duplicates, you can fall back to:

Category.find_or_create_by_name('General')

This will attempt to find it (by name), or create the record if it doesn't exist.

Respondido 24 ago 12, 06:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.