Undo scaffolding in Rails
First, if you have already run the migrations generated by the scaffold
command, you have to perform a rollback first.
rake db:rollback
You can create scaffolding using:
rails generate scaffold MyFoo
(or similar), and you can destroy/undo it using
rails destroy scaffold MyFoo
That will delete all the files created by generate
, but not any additional changes you may have made manually.
Would I need to undo a rails generate scaffold after I undo a db:migrate ?
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
how do you undo delete scaffold in rails?
Turns out, running rails destroy scaffold foo
from command line shows all files destroyed by the command — even if they don't exist. So rails destroy scaffold chocolatechip
(which I can assure you does not exist) results in:
invoke active_record
remove db/migrate/20150705235646_create_chocolatechip.rb
remove app/models/chocolatechip.rb
invoke test_unit
remove test/models/chocolatechip_test.rb
remove test/fixtures/chocolatechip.yml
invoke resource_route
route resources :chocolatechip
invoke responders_controller
remove app/controllers/chocolatechip_controller.rb
invoke erb
remove app/views/chocolatechip
remove app/views/chocolatechip/index.html.erb
remove app/views/chocolatechip/edit.html.erb
remove app/views/chocolatechip/show.html.erb
remove app/views/chocolatechip/new.html.erb
remove app/views/chocolatechip/_form.html.erb
invoke test_unit
remove test/controllers/chocolatechip_controller_test.rb
invoke helper
remove app/helpers/chocolatechip_helper.rb
invoke test_unit
invoke jbuilder
remove app/views/chocolatechip
remove app/views/chocolatechip/index.json.jbuilder
remove app/views/chocolatechip/show.json.jbuilder
invoke assets
invoke coffee
remove app/assets/javascripts/chocolatechip.coffee
invoke scss
remove app/assets/stylesheets/chocolatechip.scss
invoke scss
None of those files ever existed, but the aforementioned command shows them anyway. So basically, I never had a problem to begin with.
Ruby On Rails : How to undo nested_scaffold in rails
You can destroy nested scaffold with scaffold
rails destroy scaffold class_room/course name:string
The result:
invoke active_record
remove db/migrate/20151006093322_create_class_room_courses.rb
remove app/models/class_room/course.rb
invoke test_unit
remove test/models/class_room/course_test.rb
remove test/fixtures/class_room/courses.yml
invoke resource_route
route namespace :class_room do
resources :courses
end
invoke scaffold_controller
remove app/controllers/class_room/courses_controller.rb
invoke erb
remove app/views/class_room/courses
remove app/views/class_room/courses/index.html.erb
remove app/views/class_room/courses/edit.html.erb
remove app/views/class_room/courses/show.html.erb
remove app/views/class_room/courses/new.html.erb
remove app/views/class_room/courses/_form.html.erb
invoke test_unit
remove test/controllers/class_room/courses_controller_test.rb
invoke helper
remove app/helpers/class_room/courses_helper.rb
invoke test_unit
invoke jbuilder
remove app/views/class_room/courses
remove app/views/class_room/courses/index.json.jbuilder
remove app/views/class_room/courses/show.json.jbuilder
invoke assets
invoke coffee
remove app/assets/javascripts/class_room/courses.coffee
invoke scss
remove app/assets/stylesheets/class_room/courses.scss
invoke scss
Then you can migrate it.
rake db:migrate
I hope this help you.
What steps do you take to undo mistakes in Rails development?
Always, always put your Rails application under version control. It doesn't really matter if you want to use Git, Mercurial or SVN... regardless your choice, don't start a Rails project without a Version Control System.
A SCM tool is your global UNDO button.
rails destroy scaffold leaves back table
What I had to do was:
First I followed the steps specified by @Alex Siri.
But after doing that using
rake db:migrate
Did not add the values question,answer etc to the table, so I did the following steps
I again deleted the scaffold using the command
rails destroy scaffold level
After that I again created the scaffold using the command:
rails generate scaffold level question:string answer:string prev_q:integer next_q:integer
Finally I ran migration using
rake db:migrate
This solved my problem. I wrote all the steps so that if anyone else has the same problem then they can easily solve it.
How to reverse a 'rails generate'
rails destroy controller lalala
rails destroy model yadayada
rails destroy scaffold hohoho
Rails 3.2 adds a new d
shortcut to the command, so now you can write:
rails d controller lalala
rails d model yadayada
rails d scaffold hohoho
Related Topics
Heroku App Crash H10 - Bash: Bin/Rails: No Such File or Directory
Converting a Hexadecimal Digest to Base64 in Ruby
Ruby Block to String Instead of Executing
How to Create a Nokogiri Case Insensitive Xpath Selector
Dry Way to Assign Hash Values to an Object
Optional Arguments with Default Value in Ruby
Windows/Ruby/Rails Install --- .Cannot Load Such File -- SQLite3/Sqlite3_Native Windows
Sort a Collection of Objects by Number (Highest First) Then by Letter (Alphabetical)
How to Check If a Ruby Array Includes One of Several Values
Putting the Results of Pp (Or Anything Outputted to Console) into a String
Safe Navigation Operator (&.) for Nil
Ruby Regex Error: Incompatible Encoding Regexp Match (Ascii-8Bit Regexp with Utf-8 String)
Rails Date Format in Form Field
Ruby Forgets Local Variables During a While Loop
Allow Public Connections to Local Ruby on Rails Development Server
How to Solve Insecure World Writable Dir /Usr in Path,Mode 040777 Warning on Ruby
Ruby Design Pattern: How to Make an Extensible Factory Class