0

我的管理部分中有命名空间模型Equipment::Feature和命名空间控制器Admin::Equipment::FeaturesController。模型是通用的,用于:admin 命名空间内和公共网站。:admin我已经为和:equipment命名空间设置了路由

namespace :admin do
  namespace :equipment do
    resources :features
  end
end

这给了我以下路线:

 admin_equipment_features     GET /admin/equipment/features(.:format)          admin/equipment/features#index
                              POST /admin/equipment/features(.:format)         admin/equipment/features#create
 new_admin_equipment_feature  GET /admin/equipment/features/new(.:format)      admin/equipment/features#new
 edit_admin_equipment_feature GET /admin/equipment/features/:id/edit(.:format) admin/equipment/features#edit
 admin_equipment_feature      GET /admin/equipment/features/:id(.:format)      admin/equipment/features#show
                              PUT /admin/equipment/features/:id(.:format)      admin/equipment/features#update
                              DELETE /admin/equipment/features/:id(.:format)   admin/equipment/features#destroy

很标准的东西。但是当我解决/admin/equipment/features它时会抛出uninitialized constant Admin::Equipment::FeaturesController::Equipment异常

#index我的动作Admin::Equipment::FeaturesController看起来像

def index
  @features = Equipment::Feature.all
end

在我声明命名空间之前,它似乎确实有效Admin::Equipment。之前就像Admin::EquipmentFeaturesController

我想这是某种命名空间冲突,但我不明白 - 它来自哪里?

提前致谢!

更新 Feature模型(使用 STI 模式)

class Equipment::Feature < ActiveRecord::Base

  attr_accessible :category_id, :name_en, :name_ru, :type

  belongs_to :category, :class_name => 'Equipment::Category'

  has_many :item_features, :class_name => 'Equipment::ItemFeature'
  has_many :items, :through => :item_features

  translates :name
end

class FeatureBoolean < Equipment::Feature

end

class FeatureNumeric < Equipment::Feature

end

class FeatureString < Equipment::Feature

end

class FeatureRange < Equipment::Feature

end

UPDATE2根据以下答案 修复#index操作解决了该问题。新代码:

def index
  @features = ::Equipment::Feature.all
end
4

2 回答 2

2

我认为它现在正在寻找Featurein Admin::Equipment,而不是 in::Equipment

尝试指定没有命名空间,即

def index
  @features = ::Equipment::Feature.all
end
于 2012-06-16T15:39:16.350 回答
1

请创建这样的文件夹 app/controllers/admin/equipment/features.rb

然后将您的控制器名称编辑为 Admin::Equipment::FeaturesController

class Admin::Equipment::FeaturesController < ActiveRecord::Base

end
于 2012-06-16T15:51:30.930 回答