我的管理部分中有命名空间模型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