我将 Accept_nested_attributes_for 与以下模型一起使用:
用户型号:
class User < ActiveRecord::Base
has_many :competences
has_many :skills, :through => :competences, :foreign_key => :skill_id
accepts_nested_attributes_for :skills
end
技能模型:
class Skill < ActiveRecord::Base
has_many :competences
has_many :users, :through => :competences, :foreign_key => :user_id
end
能力模型:
class Competence < ActiveRecord::Base
belongs_to :user
belongs_to :skill
end
技能表有一个“名称”属性。如果已经存在具有相同技能名称的记录,我如何才能让 accept_nested_attributes_for 不创建新的技能记录?