diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index dc60b24a..8f2b79bd 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -61,4 +61,8 @@ class FilesController < ApplicationController end redirect_to project_files_path(@project) end + + def show_by_attachtype + + end end diff --git a/app/models/course.rb b/app/models/course.rb index d2f1abfe..9f0c42c6 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -7,6 +7,7 @@ class Course < ActiveRecord::Base belongs_to :school, :class_name => 'School', :foreign_key => :school_id #定义一个方法school,该方法通过school_id来调用School表 has_many :bid validates_presence_of :password, :term + validates_format_of :class_period, :message => "class period can only digital!", :with =>/^[1-9]\d*$/ safe_attributes 'extra', 'time', 'name', @@ -17,7 +18,14 @@ class Course < ActiveRecord::Base 'password', 'term', 'password' - + + #自定义验证 + def validate + if !class_period.match([0-9]) + errors.add_to_base("class period can only digital") + end + end + def get_endup_time begin end_time = Time.parse(self.endup_time) diff --git a/app/models/project.rb b/app/models/project.rb index 827ed099..007f7e30 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -164,6 +164,13 @@ class Project < ActiveRecord::Base @attachmenttypes = Attachmentstype.find(:all, :conditions => ["#{Attachmentstype.table_name}.typeId= ?",self.attachmenttype ]) end + #自定义验证 + def validation + if !class_period.match([0-9]) + errors.add_to_base("class period can only digital") + end + end + # 项目留言 added by fq def self.add_jour(user, notes) project = Project.find('trustie') diff --git a/app/views/files/index.html.erb b/app/views/files/index.html.erb index 7552b994..b9da42d9 100644 --- a/app/views/files/index.html.erb +++ b/app/views/files/index.html.erb @@ -174,6 +174,8 @@ div.pagination{ <% delete_allowed = User.current.allowed_to?(:manage_files, @project) %> + +