Rieles Reiniciar seed.rb
Frecuentes
Visto 2,438 veces
1
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')
2 Respuestas
2
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
0
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 ruby-on-rails or haz tu propia pregunta.