gpt4 book ai didi

ruby-on-rails - 嵌套资源错误 : Circular dependency detected while autoloading constant

转载 作者:太空宇宙 更新时间:2023-11-03 16:51:04 25 4
gpt4 key购买 nike

我尝试在 Rails 4 中使用嵌套资源,但出现以下错误:

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

所以我有一个由 devise 创建的客户端模型和一个网站模型。关系是一对多。

数据库:

    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'

我以前从未使用过嵌套资源,知道我在这里缺少什么吗?已经尝试第二天解决问题:(

提前致谢! ;)

最佳答案

可能发生的一件事(虽然我在这里看不到)是您可能直接在父类(super class)中引用类。

我遇到了这个问题,并像这样解决了它:

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

关于ruby-on-rails - 嵌套资源错误 : Circular dependency detected while autoloading constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21740592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com