我正在尝试使用命名空间重构我的路由文件。当我尝试访问路由时,我收到错误uninitialized constant Web::Admins
。
scope path: '/web' do
...
get 'admins/new' => 'web/admins#new', defaults: { format: :html }, as: :new_web_admins
get 'admins' => 'web/admins#index', defaults: { format: :html }, as: :web_admins
get 'admins/:id' => 'web/admins#show', defaults: { format: :html }, as: :show_web_admins
post 'admins' => 'web/admins#create', defaults: { foramt: :html }, as: :create_web_admins
patch 'admins/:id/edit' => 'web/admins#update', defaults: { format: :html }, as: :edit_web_admins
delete 'admins/:id' => 'web/admins#destroy', defaults: { format: :html }, as: :destroy_web_admins
...
namespace :web do
namespace :admins do
get 'new' => 'web/admins#new', defaults: { format: :html }#, as: :new_web_admins
get '/' => 'web/admins#index', defaults: { format: :html }#, as: :web_admins
get '/:id' => 'web/admins#show', defaults: { format: :html }#, as: :show_web_admins
post '/' => 'web/admins#create', defaults: { foramt: :html }#, as: :create_web_admins
patch '/:id/edit' => 'web/admins#update', defaults: { format: :html }#, as: :edit_web_admins
delete '/:id' => 'web/admins#destroy', defaults: { format: :html }#, as: :destroy_web_admins
post 'doit' => 'web/admins#doit', defaults: { format: :html }
end
end
class Web::AdminsController
...
end
答案 0 :(得分:2)
namespace :admins
需要/web/admins/
这样的路线,以便查找Web::Admins::...
顺便考虑一下RESTful路线。根据他们的标准你可以写:
namespace :web do
resources :admins
end