Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 嵌套资源错误:自动加载常量时检测到循环依赖项_Ruby On Rails_Ruby_Ruby On Rails 4_Resources_Nested - Fatal编程技术网

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

Ruby on rails 嵌套资源错误:自动加载常量时检测到循环依赖项,ruby-on-rails,ruby,ruby-on-rails-4,resources,nested,Ruby On Rails,Ruby,Ruby On Rails 4,Resources,Nested,我试图在Rails 4中使用嵌套资源,但出现以下错误: RuntimeError (Circular dependency detected while autoloading constant Client::Website::ClientWebsitesController) 所以我有一个由Desive创建的客户机模型,我得到了一个网站模型。这种关系是一对多的 数据库: create_table(:clients) do |t| ## Database authenticata

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

RuntimeError (Circular dependency detected while autoloading constant Client::Website::ClientWebsitesController)
所以我有一个由Desive创建的客户机模型,我得到了一个网站模型。这种关系是一对多的

数据库:

    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
我以前从未使用过嵌套资源,有什么想法吗?已在第二天尝试解决此问题:(


提前感谢!;)

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

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

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
类SDMObject我想问题出在您的
客户端::网站::客户端网站控制器文件上这是一个控制器-您确定它设置正确吗?此外,您还应该提供此控制器的代码&您从中引用它的视图/控制器(这些代码将显示您在调用它时可能遇到的任何问题)当问题与依赖关系无关时,有时会出现特定的错误消息-请参阅此问题以进行讨论:您需要检查控制器文件是否存在其他错误(对不存在的常量的引用是常见的触发器)。如果你仍然找不到任何东西,就把它贴在这里。@MattJones谢谢。这让我发现我的模型类名称中有一个输入错误。
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