2015-05-17 34 views
0

我有一个SubcategoriesController'未初始化的常量SubcategoriesController' - Rails的

class Categories::SubcategoriesController < ApplicationController 
    def new 
    @category = Category.find(params[:category_id]) 
    @subcategory = Subcategory.new 
    end 

    def edit 
    end 

    def create 
    end 

    def destroy 
    end 
end 

这是我的路线

resources :categories do 
    resources :subcategories, except: [:index, :show] 
    end 

当我试图访问categories_path,它抛出uninitialized constant SubcategoriesController

哪儿了我错了?

回答

1

当前路径配置预计会在app/controllers/subcategories_controller.rb中找到SubcategoriesController,但您已声明Categories::SubcategoriesController(可能位于app/controllers/categories/subcategories_controller.rb)。

尝试移动和重命名控制器,以便路由器可以找到它。

希望有帮助!