0

I installed the responder gem, ran bundle install, and wound up realizing I didn't need it. So like an idiot, I called rails delete scaffold responders and wound up deleting way more files than I needed. I didn't checked the project into Git between either step, so there's no way I can revert.

Is there a command I can use to undo this?

Makoto
  • 104,088
  • 27
  • 192
  • 230
calyxofheld
  • 1,538
  • 3
  • 24
  • 62
  • 1
    Did you ever stage your work at any point? – Makoto Jul 04 '15 at 03:31
  • 1
    your text editor might be configured to have automatic backups as well – alternative Jul 04 '15 at 04:21
  • @Makoto I did, but it's been quite some time. – calyxofheld Jul 04 '15 at 19:42
  • Run `git fsck` (do ***not*** use `git gc` at any cost until you've resolved the issue), and you may be able to recover your files. Other approaches can be found on Stack Overflow, for example, [here is one such approach](http://stackoverflow.com/questions/11621424/all-staged-but-uncommitted-files-deleted-after-issuing-git-reset-hard-head). – Makoto Jul 04 '15 at 19:51

2 Answers2

2

If you edited those files and you want that code back, no, there is no way.

If those files were pristine, you can actually reinstall responders with rails g responders:install

Francesco Belladonna
  • 11,361
  • 12
  • 77
  • 147
  • `rails g responders:install` resulted in the creation or modification of these files: lib/application_responder.rb, config/application.rb, app/controllers/application_controller.rb, app/controllers/application_controller.rb, config/locales/responders.en.yml – calyxofheld Jul 04 '15 at 19:31
  • But when I destroyed the responders scaffold, I wound up destroying wayyy more than that. Files like db/migrate/20150704025926_create_responders.rb, app/models/responder.rb, app/controllers/responders_controller.rb, app/views/responders/new.html.erb, app/views/responders/index.json.jbuilder, app/assets/stylesheets/responders.scss, etc... Were the files I deleted made by running `bundle install`? – calyxofheld Jul 04 '15 at 19:34
  • 1
    No, and if you didn't edit those files, running the command in my answer will definitely build back the files you are mentioning without creating any issues. – Francesco Belladonna Jul 04 '15 at 19:53
  • Ran the command, and all it did was rebuild the files built by my initial run of `rails g responsders:install` - not the files deleted with `rails delete scaffold responders`. – calyxofheld Jul 04 '15 at 20:47
  • 1
    `bundle install` doesn't create any file, did you run `rails generate scaffold responders` at some point? The install should build all required file for `responders` gem, as stated in the documentation – Francesco Belladonna Jul 04 '15 at 21:31
  • I didn't mention it in the initial post because I never ran it, but no, I did not run `rails generate scaffold responders`. But I just figured out my problem: if you call `rails destroy scaffold foo`, the console will show that you've deleted all the files that command normally destroys - even if those files don't exist. – calyxofheld Jul 05 '15 at 23:57
0

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.

calyxofheld
  • 1,538
  • 3
  • 24
  • 62