我使用accepts_nested_attributes_for有如下型号:accepts_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不创建新技能记录?
你有没有找到这个解决方案?我在技能上有一个与'validates:name,presence:true,uniqueness:true'完全相同的设置。当在嵌套属性表单中输入具有相同名称的技能时,我会得到唯一性验证错误。如果姓名匹配,我希望能够使用现有技能。 – scttnlsn 2014-01-22 17:33:14