2

是否可以引用app/controllers/admin/categories_controller.rbusingcategories_path而不是admin_categories_path

我正在使用 Rails 4。

# app/controllers/admin
class Admin::CategoriesController < Admin::BaseController
end

# visiting localhost:3000/admin/categories causes route not found error 'admin/categories'
scope module: "admin" do
  resources :categories
end

# visiting localhost:3000/admin/categories causes uninitialized constant CategoriesController
scope "/admin" do
  resources :categories
end
4

1 回答 1

3

我相信您必须在资源中引用控制器

scope 'admin' do
  resources :categories, controller: 'admin/categories'
end

所以路线变成了

   categories   GET    /admin/categories(.:format)          admin/categories#index
                POST   /admin/categories(.:format)          admin/categories#create
   new_category GET    /admin/categories/new(.:format)      admin/categories#new
  edit_category GET    /admin/categories/:id/edit(.:format) admin/categories#edit
       category GET    /admin/categories/:id(.:format)      admin/categories#show
                PATCH  /admin/categories/:id(.:format)      admin/categories#update
                PUT    /admin/categories/:id(.:format)      admin/categories#update
                DELETE /admin/categories/:id(.:format)      admin/categories#destroy
于 2013-04-24T22:10:19.650 回答