Rails NameError has_many中的未初始化常量:通过关系

时间:2014-12-12 13:32:04

标签: ruby-on-rails ruby associations has-many-through

我定义了以下模型:

house_firm.rb

class HouseFirm < ActiveRecord::Base
  has_many :house_firm_group_links
  has_many :house_firm_groups, through: :house_firm_group_links
end

house_firm_group.rb

class HouseFirmGroup < ActiveRecord::Base
  has_many :house_firm_group_links
  has_many :house_firms, through: :house_firm_group_links
end

house_form_group_link.rb

class HouseFirmGroupLink < ActiveRecord::Base
  belongs_to :house_firm
  belongs_to :house_firm_group
end

然而,当我这样做时:

@house_firm = HouseFirm.new
@house_firm.house_firm_groups

我收到:

NameError at /house_firms/new

uninitialized constant HouseFirm::HouseFirmGroupLink

我做错了什么,如何解决这个问题?

1 个答案:

答案 0 :(得分:6)

您在实现HouseFirmGroupLink类的文件名中有拼写错误,应将其命名为house_firm_group_link.rb