2012-06-16 160 views
0

我有名稱空間模型Equipment::Feature和命名空間控制器在我的管理部分Admin::Equipment::FeaturesController。模型是通用的,用於從:admin命名空間和公共網站。我已經設置了路由的:admin:equipment命名空間Rails 3名稱空間模型和控制器路由問題

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它拋出我Admin::Equipment::FeaturesController看起來像

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

它似乎工作,直到我宣佈Admin::Equipment命名空間uninitialized constant Admin::Equipment::FeaturesController::Equipment例外

#index行動。之前它就像Admin::EquipmentFeaturesController

我想這是某種命名空間碰撞,但我不明白它 - 它從哪裏來的?

在此先感謝!

UPDATEFeature模型(使用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

請顯示您的功能模型中的代碼。 –

+0

更新的問題。 'Feature'模型使用STI模式,並按照Rails慣例 – paulus

回答

2

我認爲現在它在Admin::Equipment尋找Feature,而不是在::Equipment

嘗試指定沒有命名空間,即

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

擁有帶STI類名的'type'列哦謝謝!有效!我不知道用'::'類型的'重置'命名空間解析的前綴命名空間。 – paulus

1

請喜歡這個程序創建的文件夾/controllers/admin/equipment/features.rb

然後編輯您的控制器名稱爲Admin :: Equipment :: Feat uresController

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

end 
+0

它現在就是這樣 – paulus

相關問題