Skip to content

rails destroy content Resource crashes with Errno::ENOENT on pages_controller.rb #168

@m-lague

Description

@m-lague

Hi,

When I try to destroy a generated content resource, rails destroy content Page crashes with an Errno::ENOENT because it attempts to operate on app/controllers/content/pages_controller.rb after that file has already been removed.

Steps to reproduce

rails generate content Page
Generates:

create  app/models/content/page.rb
create  app/controllers/content/pages_controller.rb
create  app/views/content/pages
create  app/views/content/pages/index.html.erb
create  app/views/content/pages/show.html.erb
route   resources :pages, module: :content, only: %w[index show]
insert  app/controllers/content/pages_controller.rb
create  app/content/pages/root.erb
route   root to: "content/pages#root"

rails destroy content Page
Output:

remove   app/models/content/page.rb
remove   app/controllers/content/pages_controller.rb
remove   app/views/content/pages
remove   app/views/content/pages/index.html.erb
remove   app/views/content/pages/show.html.erb
route    resources :pages, module: :content, only: %w[index show] 
subtract app/controllers/content/pages_controller.rb
... then crash:
Errno::ENOENT: No such file or directory @ rb_sysopen -
app/controllers/content/pages_controller.rb

Actual behavior

rails destroy content Page raises:

Errno::ENOENT: No such file or directory @ rb_sysopen -
app/controllers/content/pages_controller.rb

The Thor inject_into_file / inject_into_class revoke step runs after the file has already been removed.

Expected behavior

rails destroy content Page should:

  • remove the generated model, controller, and views,
  • remove the injected routes,
  • remove app/content/pages/root.erb,
  • and clean up any injected code in pages_controller.rb without crashing, skipping the revoke step if the file has already been deleted.

Environment

  • Ruby: 4.0.2
  • Rails: 8.1.2
  • Perron: 0.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions