How can I delete a resource created with the scaffold command in Ruby on Rails? If I try to overwrite it, I have problems to migrate because the table already exists!
2 Answers
First you should rollback your migration:
rake db:rollback
Then to undo a scaffold in Rails use the following command:
rails destroy scaffold YourScaffold

- 8,508
- 14
- 68
- 117
-
But then I have still problems if i wanna create a new resource with the same name, because i can't do migration 'cause the table wasn't dropped – Seba92 May 30 '14 at 08:13
-
you'll need to roll back the migration that creates the database table, using `rake db:rollback`, before you destroy the scaffold. – sevenseacat May 30 '14 at 08:18
Here's what I'd do when running into the same problem during development.
I'd first destroy the scaffolded model by running
rails d scaffold ScaffoldName
I'd then drop the database to destroy the previous migrations.
Take note: Dropping your database in production is never a good choice. I only do database dropping when in development and when I don't have any data to test with yet. If ever I have data, I put them in a seeds.rb
file and then I seed the db
To drop the database and remove all previous migrations:
rake db:drop
To restore your old migrations before the faulty scaffold, you then do:
rake db:migrate
If you have a seeds.rb for prepopulating your database:
rake db:seed

- 137
- 1
- 10