I'm new to RoR and I'm following Michael Hartl's tutorial (so feel free to correct the terminology I'm using where you see it fit). In chapter 2, I created a Users table by running these lines:
$ rails generate scaffold User name:string email:string
$ bundle exec rake db:migrate
Then, I ran the code below to try to create a Microposts table (However, I misspelled Micropost without an 'r'!)...
$ rails generate scaffold Miropost content:string user_id:integer
$ bundle exec rake db:migrate
Now I want to delete the Miropost table I created. After searching in stackoverflow.com, I understand I can undo the database migration (ie., db:migrate) by running rake db:migrate:reset
. My question is would I need to undo the "rails generate scaffold" too? And when do scaffolds cease to exist?
You can remove scaffold in the following way: Generate scaffold: $rails generate scaffold Story. If you migrated your files, perform a rollback: $rake db:rollback. Destroy or undo scaffold: $rails destroy scaffold Story.
To undo a rails generate command, run a rails destroy command. You can then edit the file and run rake db:migrate again. (See how to roll back a Migration file to rollback a specific migration or multiple migrations.)
rake db:migrate:redo - Roll back one migration and run it again. rake db:migrate:redo STEP=n - Roll back the last n migrations and run them again. rake db:migrate:up VERSION=20080906120000 - Run the up method for the given migration. rake db:migrate:down VERSION=20080906120000 - Run the down method for the given ...
Scaffolding in Ruby on Rails refers to the auto generation of a simple set of a model, views and controller usually for a single table. For example: user@localhost$ ./scripts/generate scaffold users. Would create a full CRUD (create, read, update, delete) web interface for the Users table.
First you would need to rollback the changes from db.
Assuming that the migration generated for Miropost
is the latest migration in your db
.
Just run
rake db:rollback ## This will drop the table miroposts
After this destroy the existing scaffold by :
rails destroy scaffold Miropost content:string user_id:integer
Then all you need to do is to recreate the scaffold with correct spelling and run rake db:migrate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With