我的管理部分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
答案 0 :(得分:2)
我认为现在正在Feature
中寻找Admin::Equipment
,而不是::Equipment
尝试指定没有名称空间,即
def index
@features = ::Equipment::Feature.all
end
答案 1 :(得分:1)
请创建此app / controllers / admin / equipment / features.rb
这样的文件夹然后将您的控制器名称编辑为Admin :: Equipment :: FeaturesController
class Admin::Equipment::FeaturesController < ActiveRecord::Base
end