简体   繁体   English

NameError(未初始化的常量

[英]NameError (uninitialized constant

I have get error in my attempt to visit page: 我在尝试访问页面时遇到错误:

NameError (uninitialized constant Web::Admin::Products::BrandsController::Brand):
app/controllers/web/admin/products/brands_controller.rb:3:in `index'

My Controller: 我的控制器:

app/controllers/web/admin/products/brands_controller.rb

My model: 我的模特:

app/models/product/brand.rb

My routes.rb 我的routes.rb

scope module: :web do

  namespace :admin do
    namespace :products do
      resources :brands     
    end 

    resources :products do
      scope module: :products do          
        resources :product_types
      end      
    end

  end
end

My index action in app/controllers/web/admin/products/brands_controller.rb in app/controllers/web/admin/products/brands_controller.rb索引操作

def index
    @search = Brand.all
    @brands = @search.result(distinct: true)
end

Help me , please 请帮帮我

我认为您不应为模型使用命名空间:将app/models/product/brand.rbapp/models/brand.rb

All problem in your namespaces you have 2 ways for resolve it: 命名空间中的所有问题都有两种解决方法:

  1. rename your model to Product::Brand 将您的模型重命名为Product::Brand

  2. change way to your model: 更改模型的方式:

form app/models/product/brand.rb 表格app/models/product/brand.rb

to app/models/brand.rb app/models/brand.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM