【问题标题】:Expected model.rb to define MODEL预期 model.rb 定义 MODEL
【发布时间】:2012-08-24 06:41:53
【问题描述】:

我有 3 个表 Collections、Tracks 和 ProductContributors 它们的关联如下

class Collection < ActiveRecord::Base
  has_many :product_contributors, :as => :product 
  has_many :tracks, :through => Product_contributors, :as=> :product
end

class Track < ActiveRecord::Base
 has_many :product_contributors, :as => :product 
 has_many :collections, :through => Product_contributors, :as => :product
end

class ProductContributor < < ActiveRecord::Base
  belongs_to :product, :polymorphic => true
  belongs_to :collection
  belongs_to :track
end

每当我点击产品贡献者的网址时,我都会收到以下错误:
Expected /app/models/track.rb to define TRACK
我已经浏览了this url,但无论如何都没有帮助我。我没有自动加载问题,我的所有模型都已正确加载



任何帮助将不胜感激..!!

【问题讨论】:

  • track.rb 中定义的类的名称是什么?

标签: ruby-on-rails ruby polymorphic-associations


【解决方案1】:

我敢说是因为你的 Track 课程中的错字。

has_many :collections, :through => Product_contributors, :as => :product

无效。试试:

has_many :collections, :through => :product_contributors, :as => :product

基本上,它正在尝试加载模型,但它发现关联中的错字,然后它没有加载,导致它看起来好像类不存在。我假设您在使用 Collection 类时也会遇到类似的情况。

【讨论】:

    猜你喜欢
    • 2012-01-02
    • 1970-01-01
    • 2014-06-19
    • 2017-08-20
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    相关资源
    最近更新 更多