2015-05-17 175 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)。

嘗試移動和重命名控制器,以便路由器可以找到它。

希望有幫助!