Reputation: 655
I have namespaced model Equipment::Feature
and namespaced controller in my admin part Admin::Equipment::FeaturesController
. Model is generic and is used as from within :admin
namespace and for public website. I've set up the routing for :admin
and :equipment
namespaces
namespace :admin do
namespace :equipment do
resources :features
end
end
Which gives me following routes:
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
Pretty standard stuff. But when I address /admin/equipment/features
it throws uninitialized constant Admin::Equipment::FeaturesController::Equipment
exception
#index
action in my Admin::Equipment::FeaturesController
looks like
def index
@features = Equipment::Feature.all
end
It did seem to work, until I declared Admin::Equipment
namespace. Before it was like Admin::EquipmentFeaturesController
I guess this is some sort of namespace collision, but I don't get it - where does it come from?
Thanks in advance!
UPDATE Feature
model (uses STI pattern)
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
Fixing #index
action as per answer below resolved the issue. New code:
def index
@features = ::Equipment::Feature.all
end
Upvotes: 0
Views: 660
Reputation: 662
Please create folder like this app/controllers/admin/equipment/features.rb
And then edit your controller name to Admin::Equipment::FeaturesController
class Admin::Equipment::FeaturesController < ActiveRecord::Base
end
Upvotes: 1
Reputation: 2438
I think it's now looking for Feature
in Admin::Equipment
, rather than in ::Equipment
Try specifying that there is no namespace, i.e.
def index
@features = ::Equipment::Feature.all
end
Upvotes: 2