Search code examples
ruby-on-railsruby-on-rails-3rails-routing

Namespaced Routes give me Unitialized constant Admin::Towers


The two particular routes im having issues with are admin/inspections and admin/activities. When I first save routes.rb, whichever route I load first works but the other will not, it gives me error: "Unitialized constant Admin::Towers"

I have the following routes setup.

namespace :admin do
 #...etc...    

 resources :inspections, only: [:index,:show], controller: 'towers/inspections'
 resources :activities, only: [:index], controller: 'towers/activities'
end

Solution

  • As you've namespaced your resources, your controllers should reside within app/controllers/admin/* and have a name, i.e. for inspections: class Admin::InspectionsController

    I'm guessing you would like to have:

    scope '/admin' do
      resources :inspections, only: [:index,:show], controller: 'towers/inspections'
      resources :activities, only: [:index], controller: 'towers/activities'
    end