是否可以使用app/controllers/admin/categories_controller.rb
代替categories_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
答案 0 :(得分: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