Rails destroy scaffold without previous rails g scaffold

484 views Asked by At

I'm cleaning a rails application and I have to delete a lot of files. I try to destroy scaffolds with "rails destroy scaffold x" The console output seems to remove a lot of files, but actually it doesn't.

I don't know if "rails g scaffold" was used to generate all, so my questions is: is posible to use "rails destroy scaffold" if "rails g scaffold" was not used to create that files?

2

There are 2 answers

1
Javier Rodríguez On BEST ANSWER

I discover that destroy scaffold, only generetes paths to remove files, for example:

rails d scaffold my_directory/something

That generetes the next output in console:

    invoke  active_record
      remove    db/migrate/20170901061811_create_my_directory_somethings.rb
      remove    app/models/my_directory/something.rb
      invoke    test_unit
      remove      test/models/my_directory/something_test.rb
      remove      test/fixtures/my_directory/somethings.yml
      invoke  resource_route
       route    namespace :my_directory do
    resources :somethings
  end
      invoke  scaffold_controller
      remove    app/controllers/my_directory/somethings_controller.rb
      invoke    haml
      remove      app/views/my_directory/somethings
      remove      app/views/my_directory/somethings/index.html.haml
      remove      app/views/my_directory/somethings/edit.html.haml
      remove      app/views/my_directory/somethings/show.html.haml
      remove      app/views/my_directory/somethings/new.html.haml
      remove      app/views/my_directory/somethings/_form.html.haml
      invoke    test_unit
      remove      test/controllers/my_directory/somethings_controller_test.rb
      invoke    helper
      remove      app/helpers/my_directory/somethings_helper.rb
      invoke      test_unit
      invoke    jbuilder
      remove      app/views/my_directory/somethings
      remove      app/views/my_directory/somethings/index.json.jbuilder
      remove      app/views/my_directory/somethings/show.json.jbuilder
      remove      app/views/my_directory/somethings/_my_directory_something.json.jbuilder
      invoke  assets
      invoke    coffee
      remove      app/assets/javascripts/my_directory/somethings.coffee
      invoke    scss
      remove      app/assets/stylesheets/my_directory/somethings.scss
      invoke  scss

That generates some paths where the files should be, and try to delete that files if exist, don't mind if you create that files with scaffold or manually. But if that some files doesn't exist it only skip that files without advise in console output

In my app that files wasn't create in the correct directory so rails d scaffold can't remove it

3
Jermaine Subia On

Not sure what you were told in regards to how the app was built but if they didn't use scaffolding there isn't any scaffolding to remove. I am not sure how experienced you are with rails but it consists of an MVC model. When I do refactoring I just delete out the Model, View, and controller for what I am trying to get rid of. Also, in order to delete the model and remove it from the database follow this https://stackoverflow.com/a/7106032/7039895. I hope this helps.