0

我在下面有这样的路线。如果我有这样的路线有可能吗?

#config/routes
resources :subscribers, only: [:index, :show]

namespace :admin do
    resources :subscribers, only: [:new, :edit, :update, :create, :destroy]
end

我试图运行rake 路线,结果是

admin_subscribers     POST /admin/subscribers(.:format)     admin/subscribers#create
new_admin_subscriber  GET  /admin/subscribers/new(.:format) admin/subscribers#new
edit_admin_subscriber GET  /admin/subscribers/:id/edit(.:format) admin/subscribers#edit
admin_subscriber      PUT  /admin/subscribers/:id(.:format) admin/subscribers#update
                      DELETE /admin/subscribers/:id(.:format)    admin/subscribers#destroy
subscribers           GET    /subscribers(.:format)         subscribers#index
subscriber            GET    /subscribers/:id(.:format)     subscribers#show

结果符合我的期望,但是当我运行我的 RSpec 时出现错误

Routing Error
uninitialized constant Admin::SubscribersController
Try running rake routes for more information on available routes.

我也在我的 Rspec Helper 中添加了以下代码

#spec/spec_helper.rb

Spork.each_run do
###

   if /spork/i =~ $0 || RSpec.configuration.drb?
     ActiveSupport::Dependencies.clear
   end

###

end

但是,如果我将浏览器启动到 htt**://l*alhost:3000/admin/subscribers/new,一切都很好。我错过了什么吗?

4

2 回答 2

0

文档中所述

如果你想路由/admin/subscribersSubscribersController(没有Admin::模块前缀),你可以使用scope而不是namespace

#config/routes
resources :subscribers, only: [:index, :show]

scope "/admin" do
  resources :subscribers, only: [:new, :edit, :update, :create, :destroy]
end
于 2013-05-15T16:41:51.493 回答
0

我认为您不需要将其命名为admin. 您可以适当地填写所有操作SubscribersController并设置权限createupdate

于 2013-05-15T13:52:25.630 回答