次のモデルで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
スキルテーブルには「名前」属性があります。同じスキル名のレコードがすでに存在する場合、accepts_nested_attributes_forで新しいスキルレコードを作成しないようにするにはどうすればよいですか?