Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would I need to undo a "rails generate scaffold" after I undo a "db:migrate"?

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?

like image 557
ayjay Avatar asked Apr 24 '14 20:04

ayjay


People also ask

How do you revert scaffolds in rails?

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.

How do I undo migration in rails?

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.)

How do I rollback database migration?

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 ...

What is scaffolding in Ruby?

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.


1 Answers

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

like image 69
Kirti Thorat Avatar answered Oct 17 '22 02:10

Kirti Thorat