我定义了以下模型:
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
我做错了什么,如何解决这个问题?
答案 0 :(得分:6)
您在实现HouseFirmGroupLink
类的文件名中有拼写错误,应将其命名为house_firm_group_link.rb
。