I want to delete all the files it created and roll back any changes made, but not necessarily to the database, but more to the config files.
I\'d like to automatical
Before reverting the rails generate
, please make sure you rollback the migration first.
Case 1: if you want to revert scaffold then run this command:
rails destroy scaffold MODEL_NAME
Case 2: if you want to revert model then run this command:
rails destroy model MODEL_NAME
Case 3: if you want to revert controller then run this command:
rails destroy controller CONTROLLER_NAME
Note: you can also use shortcut d
instead of destroy
.
You could use rails d model/controller/migration ...
to destroy or remove the changes generated by using the rails generate
command.
For example:
rails g model Home name:string
creates a model named home
with attribute name
. To remove the files and code generated from that command we can use
rails d model Home
This is a prototype to generate or destroy a controller or model in Rails:
rails generate/destroy controller/model [controller/model Name]
For example, if you need to generate a User Controller:
rails generate controller User
or
rails g controller User
If you want to destroy the User controller or revert to above action then use:
rails destroy controller User
or:
rails d controller User
You can destroy all things that was created same way except little thing change. For controller,
rails d controller_name (d stands for destroy)
For Model
rails d model_name
you just put d(destroy)
instead of g(generate)
in your migration.
Suppose I have created a controller named "sample" like:
rails generate controller sample
If I have to destroy this controller, all I have to do is swap generate
with destroy
, as in
rails destroy controller sample.
If you want to reverse the generation, all you have to do is swap generate
with destroy
.