From a467736a5ef031b17bda1ee7ec2ce005aaf8b483 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Fri, 30 Jan 2015 14:52:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E3=80=8A=E5=A4=9A=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=94=AF=E4=B8=80=E6=80=A7=E5=88=A4=E6=96=AD=E3=80=8B?= =?UTF-8?q?=20Signed-off-by:=20alan=20<547533434@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course_group.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/models/course_group.rb b/app/models/course_group.rb index c7fc81df4..680fa6497 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -12,8 +12,7 @@ class CourseGroup < ActiveRecord::Base before_destroy :set_member_nil attr_accessible :name - validates :name, :presence => true, :length => {:maximum => 20} - validate :unique_name_and_course + validates :name, :presence => true, :length => {:maximum => 20}, :uniqueness => { :scope => :course_id} @@ -22,10 +21,5 @@ class CourseGroup < ActiveRecord::Base self.members.update_all("course_group_id = 0") end end - private - def unique_name_and_course - if CourseGroup.where("name=? and course_id=?", name, course_id).first - errors.add(:name, :groupname_repeat) - end - end + end