ruby-on-rails 为什么“rails destroy controller ...”不删除创建的路由?

dbf7pr2w  于 2023-08-08  发布在  Ruby
关注(0)|答案(1)|浏览(129)

只是新的轨道,所以想知道这个。有什么特别的原因为什么会这样?我是否必须手动删除每次创建的路由?
我觉得很奇怪。
例如,我这样做:

$ bin/rails generate controller Articles index
      create  app/controllers/articles_controller.rb
       route  get 'articles/index'
      invoke  erb
      create    app/views/articles
      create    app/views/articles/index.html.erb
      invoke  test_unit
      create    test/controllers/articles_controller_test.rb
      invoke  helper
      create    app/helpers/articles_helper.rb
      invoke    test_unit

字符串
然后这个

$ rails destroy controller Articles
      remove  app/controllers/articles_controller.rb
      invoke  erb
      remove    app/views/articles
      invoke  test_unit
      remove    test/controllers/articles_controller_test.rb
      invoke  helper
      remove    app/helpers/articles_helper.rb
      invoke    test_unit


但是创建的路由没有被删除routes.rb文件:

Rails.application.routes.draw do
  get 'articles/index'
  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

  # Defines the root path route ("/")
  # root "articles#index"
end

pgx2nnw8

pgx2nnw81#

因为路由生成器仅在指定操作时调用:

  • https:github.com/rails/rails/blob/v7.0.6/railties/lib/rails/generators/rails/controller/controller_generator.rb#L18*
# only creates a controller, no route
$ bin/rails g controller Articles

# does it in "reverse"
$ bin/rails d controller Articles

个字符

相关问题