這是我加盟模式:軌道4:的has_many:通過錯誤
class CompanyUser < ActiveRecord::Base
belongs_to :company
belongs_to :user
end
我User
型號:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
ROLES = %w[admin requestor requestor_limited shipping_vendor].freeze
attr_accessor :temp_password
has_many :companies_users
...
end
如果我在控制檯中運行以下命令:
u = User.first
u.companies
這是我得到的錯誤:
NameError: uninitialized constant User::CompaniesUser
它應該是'has_many company_users',並且你應該在'User'模型中擁有'has_many:users,:through => company_users'。 – Pavan