1
嘿我想命名空間一堆控制器,我只希望管理員能夠訪問。例如,我要像管理/產品或管理/類別的路線,但是當我調用任何位於我控制器/ admin文件夾的控制器,我得到了以下錯誤消息超類不匹配類命名空間管理控制器
superclass mismatch for class CategoriesController
如果我重新啓動服務器權之後,我得到這個
Unable to autoload constant Admin::CategoriesController
和
Circular dependency detected while autoloading constant Admin::CategoriesController
這是我的路線
Rails.application.routes.draw do
root 'pages#home'
devise_for :admins
namespace :admin do
resources :categories, :except => [:new, :show]
resources :products
end
resources :products
resources :carts, :only => [:show]
resources :line_items, :only => [:create, :destroy]
# Shop controller
get 'shop/index
# Admin controller
get 'admin/index'
這是我的類別控制器
class CategoriesController < ApplicationController
before_filter :authenticate_admin!
def index
@categories = Category.all
@category = Category.new
end
def create
category = Category.new(categories_params)
if category.save
flash[:notice] = "You have added a new category"
redirect_to categories_path
else
flash[:error] = "An error occured"
render "index"
end
end
def edit
@category = Category.find(params[:id])
end
def update
@category = Category.find(params[:id])
if @category.update(categories_params)
flash[:notice] = "Succesfully updated #{@category[:name].titleize}"
redirect_to categories_path
else
flash[:error] = "An error occured trying to update #{@category[:name].titleize}"
render "edit"
end
end
def destroy
@category = Category.find(params[:id])
if @category.destroy
flash[:notice] = "You succesfully removed #{@category.name}"
else
flash[:error] = "An error occured trying to remove #{@category.name}"
end
redirect_to categories_path
end
private
def categories_params
params.require(:category).permit(:name)
end
end
這一直困擾我有一段時間了,因此任何幫助,將不勝感激
啊,是的,謝謝! – manis
很高興爲您提供幫助。當超時結束時請接受答案:) –
yep will do fsafaf – manis