Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rollback generated controller/model in RoR

I created, using the scaffolding, a model and controller files.
Later I discovered it would be a good idea to create the tables in the DB first...
My question, How can I role back the generated files and regenerate them now, that I have the tables in the DB?

I just started learning RoR, so right now I am not interested in best practices, just learning the tool box this FW (RoR) comes with.

And, do you have a recommendation for a good tutorial? I do know to use google, it is just that search engines don't know, yet (working on that), how to grade tutorials.
Edit: For my last question I found Learning Ruby on Rails

like image 640
Itay Moav -Malimovka Avatar asked Mar 12 '11 17:03

Itay Moav -Malimovka


People also ask

How do I rollback a controller 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 you generate scaffold in rails?

To generate a fully working scaffold for a new object, including model, controller, views, assets, and tests, use the rails g scaffold command. Then you can run rake db:migrate to set up the database table. Then you can visit http://localhost:3000/widgets and you'll see a fully functional CRUD scaffold.


3 Answers

try

rails destroy scaffold XXXXX 

one thing that I find puzzling though is that you said "Later I discovered it would be a good idea to create the tables in the DB first..."

Well, rails creates a migration file for you when you run the generator in the first place, and this file will create your DB tables and fields when you run it using rake db:migrate

PS - here's a few good tutorials for you:

  • rails tutorial ebook
  • rails demo site
  • rails 4 zombies
like image 105
stephenmurdoch Avatar answered Sep 25 '22 14:09

stephenmurdoch


You can rollback controller.

rails destroy controller [controller] 
like image 29
ultrakain Avatar answered Sep 23 '22 14:09

ultrakain


You can delete all the files Rails created -- just look at the printout on your command line, see what files rails created, and delete them.

I don't know why you would want to create all the tables in the db, but that's fine, I guess. I prefer to let rails do it. Either way, Rails won't mind. You can always add / change fields using Rails, even if you created the tables outside Rails.

Ryan Bates' Railscasts are excellent tutorials.

like image 32
fengolly Avatar answered Sep 23 '22 14:09

fengolly