0
votes

Hi I'm getting this error

Circular dependency detected while autoloading constant Subdomain::Settings::ThemesController

in my Rails 4.0 app whenever I try to access the stated controller. In fact I get similar errors for any of the other controllers name-spaced with the themes controller.

I have the following controllers name-spaced under Settings which itself is name-spaced under Subdomain.

Are these controllers defined correctly? Can anyone spot why this circular dependency error is cropping up?

# app/controllers/subdomain/settings/security_controller.rb
module Subdomain
  class Settings::SecurityController < BaseController  
    def edit
      ...
    end
  end
end

# app/controllers/subdomain/settings/themes_controller.rb
module Subdomain
  class Settings::ThemesController < BaseController
    def edit
       ...
    end
  end
end

# app/controllers/subdomain/settings/profiles_controller.rb
module Subdomain
  class Settings::ProfilesController < BaseController
    def edit
      ...
    end
  end
end

# app/controllers/subdomain/base_controller.rb
class Subdomain::BaseController < ApplicationController 
   ...
end

And the following routes configuration

MyApp::Application.routes.draw do

  constraints(Constraints::SubdomainRequired) do 

    scope :module => :subdomain do 
      namespace 'settings' do
        root to: 'security#edit'
        resource :theme,    only: [:create, :edit, :update], :controller => 'themes'
        resource :profile,  only: [:edit, :update], :controller => 'profiles'
        resource :security,  only: [:edit, :update], :controller => 'security'
      end
    end

  end
end
1
Could you post some code in your actions? - Tiago Farias
# app/controllers/subdomain/settings/settings_controller.rb ... shouldn't it be profiles_controller.rb ? - Tiago Farias
sorry that filename was just a typo here on stackoverflow. The codebase is correct. Ill update here. Ill add more code later as im on the go at the moment - robodisco

1 Answers

1
votes

The solution was I needed to rewrite each controller like so

module Subdomain
  module Settings
    class ProfileController 
      ...

instead of

module Subdomain
  class Settings::ProfileController