Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
parent
8f1249390a
commit
24a8f4fe7d
|
@ -273,6 +273,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
if valid_attr.eql?('name')
|
||||
faker.name = valid_value
|
||||
# faker.course_id = @course.id
|
||||
faker.valid?
|
||||
req[:valid] = faker.errors[:name].blank?
|
||||
req[:message] = faker.errors[:name]
|
||||
|
|
|
@ -12,11 +12,20 @@ class CourseGroup < ActiveRecord::Base
|
|||
before_destroy :set_member_nil
|
||||
|
||||
attr_accessible :name
|
||||
validates :name, :presence => true, :length => {:maximum => 20},
|
||||
:uniqueness => {case_sensitive: false}
|
||||
validates :name, :presence => true, :length => {:maximum => 20}
|
||||
validate_on_create :unique_name_and_course
|
||||
|
||||
|
||||
|
||||
def set_member_nil
|
||||
if self.members && self.members.count > 0
|
||||
self.members.update_all("course_group_id = 0")
|
||||
end
|
||||
end
|
||||
private
|
||||
def unique_name_and_course
|
||||
if CourseGroup.find(:conditions => ["name=? and course_id=?", name, course_id]).first
|
||||
errors.add_to_base("该班名已被使用!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue