我是否正确地命名了控制器?获得循环依赖性错误

时间:2014-07-23 04:31:47

标签: ruby-on-rails

嗨,我收到此错误

  

自动加载常量时检测到循环依赖性   子域::设置:: ThemesController

每当我尝试访问所述控制器时,在我的Rails 4.0应用程序中

。实际上,我得到了与主题控制器间隔开的任何其他控制器的类似错误。

我在“设置”下面有以下控制器名称,这些控件本身在“子域”下是名称间隔的。

这些控制器是否正确定义?谁能发现为什么这个循环依赖性错误正在出现?

# 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

以下路线配置

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 个答案:

答案 0 :(得分:1)

解决方案是我需要像这样重写每个控制器

module Subdomain
  module Settings
    class ProfileController 
      ...

而不是

module Subdomain
  class Settings::ProfileController