有多对多关系,但不断收到同样的错误:ActiveModel :: UnknownAttributeError:EmployeeSkill的未知属性'employee_id'。我已经检查了我的模型,看起来我有两个ID,所以不知道该怎么做?
class Skill < ApplicationRecord
validates :skill_name, presence: true, length: { minimum: 3, maximum: 30}
validates_uniqueness_of :skill_name
has_many :employee_skills
has_many :employees, through: :employee_skills
end
...
class Employee < ApplicationRecord
before_save { self.email = email.downcase }
#validates :email, presence: true, length: { maximum: 30 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
has_many :employee_skills
has_many :skills, through: :employee_skills
end
...
class EmployeeSkill < ApplicationRecord
belongs_to :employee
belongs_to :skill
end
答案 0 :(得分:0)
1)检查迁移文件和数据库中是否有相应的ID。
2)重启服务器(很奇怪但有时需要)。
您的代码看起来不错,所以我认为是我提到的两种情况之一。
此致