嵌套资源错误:自动加载常量时检测到循环依赖项



我正在尝试使用 Rails 4 中的嵌套资源,但收到以下错误:

RuntimeError (Circular dependency detected while autoloading constant Client::Website::ClientWebsitesController)

所以我有一个由 Design 创建的客户端模型,我有一个网站模型。这种关系是一对多的。

数据库:

    create_table(:clients) do |t|
  ## Database authenticatable
  t.string :email,              :null => false, :default => ""
  t.string :encrypted_password, :null => false, :default => ""
  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at
  ## Rememberable
  t.datetime :remember_created_at
  ## Trackable
  t.integer  :sign_in_count, :default => 0, :null => false
  t.datetime :current_sign_in_at
  t.datetime :last_sign_in_at
  t.string   :current_sign_in_ip
  t.string   :last_sign_in_ip
  ## Confirmable
  # t.string   :confirmation_token
  # t.datetime :confirmed_at
  # t.datetime :confirmation_sent_at
  # t.string   :unconfirmed_email # Only if using reconfirmable
  ## Lockable
  # t.integer  :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at

  t.timestamps
end
    create_table :websites do |t|
  t.string :host
  t.string :name
  t.text :description
  t.text :code #integration code, that field will be filled after the website is created
  t.integer :client_id
  t.timestamps
end

模型:

class Client < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  has_many :websites
  has_many :partner_profits
  belongs_to :subscription_plan
end
class Website < ActiveRecord::Base
    belongs_to :client
    has_many :questions
    has_one :popup_skin
end

路线:

  devise_for :admins
  devise_for :partners
  devise_for :clients
    resources :clients do
        resources :websites, controller: 'client/website/client_websites'
    end
  root to: 'frontend#index'

以前从未使用过嵌套资源,任何想法我在这里缺少什么?尝试解决问题

第二天已经:(

提前感谢! ;)

可能发生的一件事(尽管我在这里看不到)是您可能直接在类的超类中引用类。

我遇到了这个问题,并像这样修复它:

class SDMObject < ActiveRecord::Base
  # simplified for example
  LOCAL_CLASSES = [Tenant] # WRONG! Causes circular dependency
  LOCAL_CLASSES = ['Tenant'] # OK! Just evaluate to the class when needed
end
class Tenant < SDMObject
end

最新更新