course class period
This commit is contained in:
parent
40d8ec6c6e
commit
6af11fea68
|
@ -35,7 +35,7 @@ class Course < ActiveRecord::Base
|
||||||
:delete_permission => :manage_files
|
:delete_permission => :manage_files
|
||||||
|
|
||||||
validates_presence_of :password, :term,:name
|
validates_presence_of :password, :term,:name
|
||||||
validates_format_of :class_period, :with =>/^[1-9]\d*$/
|
validates_format_of :class_period, :with =>/^\d*$/
|
||||||
#validates_format_of :name,:with =>/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/
|
#validates_format_of :name,:with =>/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/
|
||||||
|
|
||||||
before_save :self_validate
|
before_save :self_validate
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
class Legacy
|
||||||
|
def self.clear_period
|
||||||
|
begin
|
||||||
|
count = 0
|
||||||
|
puts '---------------------'
|
||||||
|
|
||||||
|
Course.transaction do
|
||||||
|
Course.all.each do |course|
|
||||||
|
if course.class_period =~ /^\D*$/
|
||||||
|
count += 1
|
||||||
|
puts "[#{course.id}]: #{course.name}"
|
||||||
|
puts "period #{course.class_period} ===> 0"
|
||||||
|
puts '---------------------'
|
||||||
|
course.class_period = '0'
|
||||||
|
course.save
|
||||||
|
end
|
||||||
|
end # each end
|
||||||
|
end # transaction end
|
||||||
|
|
||||||
|
puts "clean period count: #{count}"
|
||||||
|
rescue Exception => ex
|
||||||
|
puts "*** transaction abored!"
|
||||||
|
puts "*** errors: #{ex.message}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,8 @@
|
||||||
|
desc "migrate old data."
|
||||||
|
|
||||||
|
namespace :legacy do
|
||||||
|
desc "migrate Course class period data"
|
||||||
|
task :clear_period => :environment do
|
||||||
|
Legacy.clear_period
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue