diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index dcb9a3bc3..cac763344 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -606,10 +606,10 @@ class GraduationTasksController < ApplicationController end def graduation_task_params - tip_exception("task_type参数不能为空") if params[:task_type].blank? - tip_exception("name参数不能为空") if params[:name].blank? - tip_exception("name参数不能超过60个字符") if params[:name].length > 60 #6.11 -hs - tip_exception("description参数不能为空") if params[:description].blank? + tip_exception("类型参数不能为空") if params[:task_type].blank? + tip_exception("名称不能为空") if params[:name].blank? + tip_exception("名称不能超过60个字符") if params[:name].length > 60 #6.11 -hs + tip_exception("描述不能为空") if params[:description].blank? params.require(:graduation_task).permit(:task_type, :name, :description) end diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 3c76972b8..a4d72371c 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -144,7 +144,7 @@ class MemosController < ApplicationController def reply tip_exception("parent_id不能为空") if params[:parent_id].blank? tip_exception("content不能为空") if params[:content].blank? - tip_exception("content不能超过1000字符") if params[:content].length > 1000 + tip_exception("内容不能超过1000字符") if params[:content].length > 1000 ActiveRecord::Base.transaction do begin diff --git a/app/forms/examination_banks/save_exam_form.rb b/app/forms/examination_banks/save_exam_form.rb index b84b32eb1..1fc690a2f 100644 --- a/app/forms/examination_banks/save_exam_form.rb +++ b/app/forms/examination_banks/save_exam_form.rb @@ -6,7 +6,7 @@ class ExaminationBanks::SaveExamForm validates :discipline_id, presence: true validates :sub_discipline_id, presence: true validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true } - validates :name, presence: true, length: { maximum: 60 } + validates :name, presence: true, length: { maximum: 60, too_long: "名称不能超过60个字符" } validate :validate_duration def validate_duration diff --git a/app/forms/item_banks/save_item_form.rb b/app/forms/item_banks/save_item_form.rb index 2bfd99fc3..d0a5649db 100644 --- a/app/forms/item_banks/save_item_form.rb +++ b/app/forms/item_banks/save_item_form.rb @@ -7,8 +7,8 @@ class ItemBanks::SaveItemForm validates :sub_discipline_id, presence: true validates :item_type, presence: true, inclusion: {in: %W(SINGLE MULTIPLE JUDGMENT COMPLETION SUBJECTIVE PRACTICAL PROGRAM)} validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true } - validates :name, presence: true, length: { maximum: 1000 } - validates :analysis, length: { maximum: 1000 } + validates :name, presence: true, length: { maximum: 1000, too_long: "题干不能超过1000个字符" } + validates :analysis, length: { maximum: 1000, too_long: "解析不能超过1000个字符" } def validate! super @@ -27,7 +27,7 @@ class ItemBanks::SaveItemForm attr_accessor :choice_text, :is_answer - validates :choice_text, presence: true, length: { maximum: 100 } + validates :choice_text, presence: true, length: { maximum: 500, too_long: "选项不能超过500个字符" } validates :is_answer, presence: true, inclusion: {in: 0..1}, numericality: { only_integer: true } end end \ No newline at end of file diff --git a/app/forms/validate/user.rb b/app/forms/validate/user.rb index 0f8f5e9ba..c378a36c4 100644 --- a/app/forms/validate/user.rb +++ b/app/forms/validate/user.rb @@ -4,7 +4,7 @@ module Validate attr_accessor :nickname, :lastname - validates :nickname, presence: true, length: { maximum: 10 } + validates :nickname, presence: true, length: { maximum: 10, too_long: "昵称不能超过10个字符" } validates :lastname, presence: true end end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index ac051428f..64531db46 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -25,7 +25,7 @@ class Attachment < ApplicationRecord scope :search_by_container, -> (ids) {where(container_id: ids)} scope :unified_setting, -> {where("unified_setting = ? ", 1)} - validates_length_of :description, maximum: 100 + validates_length_of :description, maximum: 100, message: "资源描述不能超过100个字符" DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e9bef0c9d..4cada46bc 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -28,7 +28,7 @@ class Challenge < ApplicationRecord scope :fields_for_list, -> { select([:id, :subject, :st, :score, :position, :shixun_id]) } - validates :task_pass, length: { maximum: 10000 } + validates :task_pass, length: { maximum: 10000, too_long: "过关任务不能超过10000个字符" } after_commit :create_diff_record diff --git a/app/models/challenge_answer.rb b/app/models/challenge_answer.rb index d3fd69cd0..8fc3c4a21 100644 --- a/app/models/challenge_answer.rb +++ b/app/models/challenge_answer.rb @@ -3,7 +3,7 @@ class ChallengeAnswer < ApplicationRecord belongs_to :challenge has_many :game_answers, :dependent => :destroy - validates :contents, length: { maximum: 5000 } + validates :contents, length: { maximum: 5000 , too_long: "答案内容不能超过5000个字符"} def view_answer_time(user_id) game_answers.where(user_id: user_id).last&.view_time diff --git a/app/models/challenge_choose.rb b/app/models/challenge_choose.rb index 2b8858f21..9a73fbc0a 100644 --- a/app/models/challenge_choose.rb +++ b/app/models/challenge_choose.rb @@ -4,6 +4,6 @@ class ChallengeChoose < ApplicationRecord has_many :challenge_tags, :dependent => :destroy has_many :challenge_questions, dependent: :destroy - validates :subject, length: { maximum: 1000 } + validates :subject, length: { maximum: 1000, too_long: "题干不能超过1000个字符" } end diff --git a/app/models/challenge_question.rb b/app/models/challenge_question.rb index 959b033f9..7267f1bb4 100644 --- a/app/models/challenge_question.rb +++ b/app/models/challenge_question.rb @@ -1,6 +1,6 @@ class ChallengeQuestion < ApplicationRecord belongs_to :challenge_choose - validates :option_name, length: { maximum: 500 } + validates :option_name, length: { maximum: 500, too_long: "选项不能超过500个字符" } end diff --git a/app/models/chart_rule.rb b/app/models/chart_rule.rb index de8fceaf1..532c7f0e7 100644 --- a/app/models/chart_rule.rb +++ b/app/models/chart_rule.rb @@ -2,5 +2,5 @@ class ChartRule < ApplicationRecord belongs_to :competition belongs_to :competition_stage, optional: true - validates :content, length: { maximum: 1000 } + validates :content, length: { maximum: 1000, too_long: "内容不能超过1000个字符" } end diff --git a/app/models/competition.rb b/app/models/competition.rb index 1d10e2032..90f2f63da 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -33,7 +33,7 @@ class Competition < ApplicationRecord has_many :competition_prizes, dependent: :destroy has_many :competition_prize_users, dependent: :destroy - validates :introduction, length: { maximum: 500 } + validates :introduction, length: { maximum: 500, too_long: "简介不能超过500个字符" } before_save :set_laboratory after_create :create_competition_modules diff --git a/app/models/competition_module_md_content.rb b/app/models/competition_module_md_content.rb index 936ded8ef..919859236 100644 --- a/app/models/competition_module_md_content.rb +++ b/app/models/competition_module_md_content.rb @@ -5,6 +5,6 @@ class CompetitionModuleMdContent < ApplicationRecord # validates :name, presence: true validates :content, presence: true - validates :content, length: { maximum: 10000 } + validates :content, length: { maximum: 10000 , too_long: "内容不能超过10000个字符"} end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb index 83d2bb56e..5808d2295 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -108,7 +108,7 @@ class Course < ApplicationRecord NORMAL = 6 # 普通用户 Anonymous = 7 # 普未登录 - validates :name, presence: true, length: { maximum: 60 } + validates :name, presence: true, length: { maximum: 60, too_long: "课堂名称不能超过60个字符" } before_save :set_laboratory after_create :create_board_sync, :act_as_course_activity, :send_tiding diff --git a/app/models/course_group.rb b/app/models/course_group.rb index 9486c9043..b49f88bde 100644 --- a/app/models/course_group.rb +++ b/app/models/course_group.rb @@ -9,7 +9,7 @@ class CourseGroup < ApplicationRecord has_many :homework_group_settings, :dependent => :destroy scope :by_group_ids, lambda { |ids| where(id: ids)} - validates :name, length: { maximum: 60 } + validates :name, length: { maximum: 60, too_long: "分班名称不能超过60个字符" } validates_uniqueness_of :name, scope: :course_id, message: "不能创建相同名称的分班" after_create :generate_invite_code diff --git a/app/models/course_module.rb b/app/models/course_module.rb index 641c70425..a1b6a7345 100644 --- a/app/models/course_module.rb +++ b/app/models/course_module.rb @@ -5,7 +5,7 @@ class CourseModule < ApplicationRecord # 二级目录 has_many :course_second_categories - validates :module_name, length: { maximum: 20 } + validates :module_name, length: { maximum: 20, too_long: "目录名称不能超过20个字符" } scope :not_hidden, -> { where(hidden: 0) } scope :graduation_module, -> { where(module_type: "graduation") } diff --git a/app/models/course_second_category.rb b/app/models/course_second_category.rb index 630b74807..6a0ae24bb 100644 --- a/app/models/course_second_category.rb +++ b/app/models/course_second_category.rb @@ -5,7 +5,7 @@ class CourseSecondCategory < ApplicationRecord belongs_to :course_module has_many :homework_commons - validates :name, length: { maximum: 60 } + validates :name, length: { maximum: 60, too_long: "名称不能超过60个字符" } def category_type_str category_type == "graduation" && name == "毕设选题" ? "graduation_topics" : ( diff --git a/app/models/course_stage.rb b/app/models/course_stage.rb index f105e25f6..c29737484 100644 --- a/app/models/course_stage.rb +++ b/app/models/course_stage.rb @@ -4,6 +4,6 @@ class CourseStage < ApplicationRecord has_many :course_stage_shixuns, -> { order("course_stage_shixuns.position ASC") }, dependent: :destroy has_many :shixuns, :through => :course_stage_shixuns - validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 300 } + validates :name, length: { maximum: 60 , too_long: "章节名称不能超过60个字符"} + validates :description, length: { maximum: 1000, too_long: "章节描述不能超过1000个字符" } end diff --git a/app/models/discuss.rb b/app/models/discuss.rb index f35ca4751..743a436e0 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -13,7 +13,7 @@ class Discuss < ApplicationRecord belongs_to :challenge, optional: true validate :validate_sensitive_string - validates :content, length: { maximum: 1000 } + validates :content, length: { maximum: 1000, too_long: "内容不能超过1000个字符" } after_create :send_tiding diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 1fd84d1f7..86e85b2d0 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -19,8 +19,8 @@ class Exercise < ApplicationRecord scope :exercise_search, lambda { |keywords| where("exercise_name LIKE ?", "%#{keywords}%") unless keywords.blank?} - validates :exercise_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } - validates :exercise_description, length: { maximum: 100 } + validates :exercise_name, length: { maximum: 60, too_long: "试卷名称不能超过60个字符" } + validates :exercise_description, length: { maximum: 100, too_long: "试卷须知不能超过100个字符" } after_create :create_exercise_list diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 00c08dd77..fb9c8d51f 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -11,6 +11,6 @@ class ExerciseAnswer < ApplicationRecord scope :exercise_answer_is_right, -> {where("score > ?",0.0)} #判断答案是否正确,根据分数总和大于0 scope :score_reviewed, lambda {where("score >= ?",0.0)} #是否评分,用于判断主观题的 - validates :answer_text, length: { maximum: 5000 } + validates :answer_text, length: { maximum: 5000, too_long: "答案不能超过5000个字符" } end \ No newline at end of file diff --git a/app/models/exercise_answer_comment.rb b/app/models/exercise_answer_comment.rb index 110efc737..62c7360c9 100644 --- a/app/models/exercise_answer_comment.rb +++ b/app/models/exercise_answer_comment.rb @@ -7,5 +7,5 @@ class ExerciseAnswerComment < ApplicationRecord scope :search_answer_comments, lambda {|name,ids| where("#{name}":ids)} - validates :comment, length: { maximum: 100 } + validates :comment, length: { maximum: 100, too_long: "评语不能超过100个字符" } end diff --git a/app/models/exercise_bank.rb b/app/models/exercise_bank.rb index 067d080b5..fb089ecbc 100644 --- a/app/models/exercise_bank.rb +++ b/app/models/exercise_bank.rb @@ -18,7 +18,7 @@ class ExerciseBank < ApplicationRecord scope :exercise_bank_search, lambda { |keywords| where("name LIKE ?", "%#{keywords}%") unless keywords.blank?} - validates :name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } - validates :description, length: { maximum: 100, too_long: "100 characters is the maximum allowed" } + validates :name, length: { maximum: 60, too_long: "试卷名称不能超过60个字符" } + validates :description, length: { maximum: 100, too_long: "试卷须知不能超过100个字符" } end \ No newline at end of file diff --git a/app/models/exercise_bank_choice.rb b/app/models/exercise_bank_choice.rb index 8f1dc9028..542b27e97 100644 --- a/app/models/exercise_bank_choice.rb +++ b/app/models/exercise_bank_choice.rb @@ -5,6 +5,6 @@ class ExerciseBankChoice < ApplicationRecord scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 - validates :choice_text, length: { maximum: 500 } + validates :choice_text, length: { maximum: 500, too_long: "选项不能超过500个字符" } end \ No newline at end of file diff --git a/app/models/exercise_bank_question.rb b/app/models/exercise_bank_question.rb index fbb6da88f..4857b1a55 100644 --- a/app/models/exercise_bank_question.rb +++ b/app/models/exercise_bank_question.rb @@ -11,7 +11,7 @@ class ExerciseBankQuestion < ApplicationRecord scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 - validates :question_title, length: { maximum: 1000 } + validates :question_title, length: { maximum: 1000, too_long: "题干不能超过1000个字符" } def question_type_name case self.question_type diff --git a/app/models/exercise_bank_standard_answer.rb b/app/models/exercise_bank_standard_answer.rb index 9bfbd67aa..4eabd2790 100644 --- a/app/models/exercise_bank_standard_answer.rb +++ b/app/models/exercise_bank_standard_answer.rb @@ -4,6 +4,6 @@ class ExerciseBankStandardAnswer < ApplicationRecord #attr_accessible :answer_text scope :standard_by_ids, lambda { |s| where(exercise_bank_choice_id: s) } - validates :answer_text, length: { maximum: 5000 } + validates :answer_text, length: { maximum: 5000, too_long: "参考答案不能超过5000个字符" } end \ No newline at end of file diff --git a/app/models/exercise_choice.rb b/app/models/exercise_choice.rb index 54b844ad9..1d3e78d8e 100644 --- a/app/models/exercise_choice.rb +++ b/app/models/exercise_choice.rb @@ -7,6 +7,6 @@ class ExerciseChoice < ApplicationRecord scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 - validates :choice_text, length: { maximum: 500 } + validates :choice_text, length: { maximum: 500, too_long: "选项不能超过500个字符" } end \ No newline at end of file diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 3f1a49625..ea588cba5 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -16,7 +16,7 @@ class ExerciseQuestion < ApplicationRecord scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 - validates :question_title, length: { maximum: 1000 } + validates :question_title, length: { maximum: 1000, too_long: "题干不能超过1000个字符" } def question_type_name diff --git a/app/models/exercise_standard_answer.rb b/app/models/exercise_standard_answer.rb index ccf5c1203..d527809ef 100644 --- a/app/models/exercise_standard_answer.rb +++ b/app/models/exercise_standard_answer.rb @@ -6,5 +6,5 @@ class ExerciseStandardAnswer < ApplicationRecord scope :find_standard_answer_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :standard_by_ids, lambda { |s| where(exercise_choice_id: s) } - validates :answer_text, length: { maximum: 5000 } + validates :answer_text, length: { maximum: 5000, too_long: "参考答案不能超过5000个字符" } end diff --git a/app/models/graduation_task.rb b/app/models/graduation_task.rb index c9838954a..9776eb564 100644 --- a/app/models/graduation_task.rb +++ b/app/models/graduation_task.rb @@ -29,8 +29,8 @@ class GraduationTask < ApplicationRecord belongs_to :gtask_bank, optional: true - validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 5000 } + validates :name, length: { maximum: 60, too_long: "任务名称不能超过60个字符" } + validates :description, length: { maximum: 5000, too_long: "任务描述不能超过5000个字符" } # 未提交 scope :unfinished, -> {where(status: 0)} diff --git a/app/models/graduation_topic.rb b/app/models/graduation_topic.rb index 294bfa785..96e7ea353 100644 --- a/app/models/graduation_topic.rb +++ b/app/models/graduation_topic.rb @@ -19,10 +19,8 @@ class GraduationTopic < ApplicationRecord #after_create :act_as_course_activity # 课题名称和描述字段长度限制 - validates :name, length: { maximum: 60, - too_long: "60 characters is the maximum allowed" } - validates :description, length: { maximum: 5000, - too_long: "5000 characters is the maximum allowed" } + validates :name, length: { maximum: 60, too_long: "选题名称不能超过60个字符" } + validates :description, length: { maximum: 5000, too_long: "选题描述不能超过5000个字符" } def status_name case self.status diff --git a/app/models/graduation_work.rb b/app/models/graduation_work.rb index 7fb0ecc24..33f09d2f8 100644 --- a/app/models/graduation_work.rb +++ b/app/models/graduation_work.rb @@ -19,7 +19,7 @@ class GraduationWork < ApplicationRecord # has_many :formal_graduation_task_group_assignations, -> { formal }, class_name: "GraduationTaskGroupAssignation" # has_many :temporary_graduation_task_group_assignations, -> { temporary }, class_name: "GraduationTaskGroupAssignation" - validates :description, length: { maximum: 5000 } + validates :description, length: { maximum: 5000, too_long: "作品描述不能超过5000个字符" } scope :has_committed, lambda { where("work_status != 0") } diff --git a/app/models/graduation_work_score.rb b/app/models/graduation_work_score.rb index 853b996a1..71bd9e00f 100644 --- a/app/models/graduation_work_score.rb +++ b/app/models/graduation_work_score.rb @@ -5,5 +5,5 @@ class GraduationWorkScore < ApplicationRecord belongs_to :graduation_task has_many :attachments, as: :container, dependent: :destroy - validates :comment, length: { maximum: 1000 } + validates :comment, length: { maximum: 1000, too_long: "评语不能超过1000个字符" } end diff --git a/app/models/gtask_bank.rb b/app/models/gtask_bank.rb index f9d38d33f..5e9b580c4 100644 --- a/app/models/gtask_bank.rb +++ b/app/models/gtask_bank.rb @@ -9,6 +9,6 @@ class GtaskBank < ApplicationRecord scope :myself, ->(user_id) { where(user_id: user_id)} scope :is_public, -> { where(:is_public => true) } - validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 5000 } + validates :name, length: { maximum: 60, too_long: "任务名称不能超过60个字符" } + validates :description, length: { maximum: 5000, too_long: "任务描述不能超过5000个字符" } end diff --git a/app/models/gtopic_bank.rb b/app/models/gtopic_bank.rb index fe9f184eb..76ed122e4 100644 --- a/app/models/gtopic_bank.rb +++ b/app/models/gtopic_bank.rb @@ -10,8 +10,6 @@ class GtopicBank < ApplicationRecord # 课题名称和描述字段长度限制 - validates :name, length: { maximum: 60, - too_long: "60 characters is the maximum allowed" } - validates :description, length: { maximum: 5000, - too_long: "5000 characters is the maximum allowed" } + validates :name, length: { maximum: 60, too_long: "选题名称不能超过60个字符" } + validates :description, length: { maximum: 5000, too_long: "选题描述不能超过5000个字符" } end diff --git a/app/models/hack.rb b/app/models/hack.rb index e89212cc3..d0a874f76 100644 --- a/app/models/hack.rb +++ b/app/models/hack.rb @@ -2,8 +2,8 @@ class Hack < ApplicationRecord # status: 0 未发布; 1已发布 # diffcult: 难度 1:简单;2:中等; 3:困难 # 编程题 - validates_length_of :name, maximum: 60 - validates_length_of :description, maximum: 5000 + validates_length_of :name, maximum: 60, message: "名称不能超过60个字符" + validates_length_of :description, maximum: 5000, message: "描述不能超过5000个字符" validates :description, presence: { message: "描述不能为空" } validates :name, presence: { message: "名称不能为空" } # 测试集 diff --git a/app/models/hack_set.rb b/app/models/hack_set.rb index 9b03ee8d0..dd4cac7b2 100644 --- a/app/models/hack_set.rb +++ b/app/models/hack_set.rb @@ -1,6 +1,6 @@ class HackSet < ApplicationRecord - validates_length_of :input, maximum: 1000 - validates_length_of :output, maximum: 1000 + validates_length_of :input, maximum: 1000, message: "测试集输入不能超过5000个字符" + validates_length_of :output, maximum: 1000, message: "测试集输出不能超过5000个字符" validates :input, presence: { message: "测试集输入不能为空" } validates :output, presence: { message: "测试集输出不能为空" } validates_uniqueness_of :input, scope: [:hack_id, :input], message: "多个测试集的输入不能相同" diff --git a/app/models/homework_bank.rb b/app/models/homework_bank.rb index d6db7bfab..e4f941375 100644 --- a/app/models/homework_bank.rb +++ b/app/models/homework_bank.rb @@ -10,7 +10,7 @@ class HomeworkBank < ApplicationRecord scope :is_public, -> { where(is_public: true)} scope :myself, ->(user_id) { where(user_id: user_id)} - validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 15000 } - validates :reference_answer, length: { maximum: 15000 } + validates :name, length: { maximum: 60, too_long: "作业名称不能超过60个字符" } + validates :description, length: { maximum: 15000, too_long: "作业描述不能超过15000个字符" } + validates :reference_answer, length: { maximum: 15000, too_long: "参考答案不能超过15000个字符" } end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 58b52bdd2..040ab65f9 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -35,10 +35,10 @@ class HomeworkCommon < ApplicationRecord # 学生的查重情况 has_many :homework_review_results, :dependent => :destroy - validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 15000 } - validates :explanation, length: { maximum: 5000 } - validates :reference_answer, length: { maximum: 15000 } + validates :name, length: { maximum: 60, too_long: "作业名称不能超过60个字符" } + validates :description, length: { maximum: 15000, too_long: "作业描述不能超过15000个字符" } + validates :explanation, length: { maximum: 5000, too_long: "说明不能超过5000个字符" } + validates :reference_answer, length: { maximum: 15000, too_long: "参考答案不能超过15000个字符" } # after_update :update_activity before_destroy :update_homework_bank_quotes diff --git a/app/models/inform.rb b/app/models/inform.rb index dc979ef32..ce549b2b9 100644 --- a/app/models/inform.rb +++ b/app/models/inform.rb @@ -1,8 +1,8 @@ class Inform < ApplicationRecord belongs_to :container, polymorphic: true, optional: true - validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 5000 } + validates :name, length: { maximum: 60, too_long: "名称不能超过60个字符" } + validates :description, length: { maximum: 5000, too_long: "内容不能超过5000个字符" } has_many :attachments, as: :container, dependent: :destroy diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 66ab98c9b..e1482d52b 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -26,7 +26,7 @@ class JournalsForMessage < ApplicationRecord # "is_comprehensive_evaluation", # 1 教师评论、2 匿评、3 留言 # "hidden", 隐藏、 - validates :notes, length: { maximum: 1000 } + validates :notes, length: { maximum: 1000, too_long: "内容不能超过1000个字符" } after_create :send_tiding diff --git a/app/models/library.rb b/app/models/library.rb index 982db732b..e9920c7b4 100644 --- a/app/models/library.rb +++ b/app/models/library.rb @@ -13,7 +13,7 @@ class Library < ApplicationRecord has_one :praise_tread_cache, foreign_key: :object_id has_many :praise_treads, as: :praise_tread_object, dependent: :destroy - validates :content, length: { maximum: 5000 } + validates :content, length: { maximum: 5000, too_long: "内容不能超过5000个字符" } validates :uuid, presence: true, uniqueness: true diff --git a/app/models/memo.rb b/app/models/memo.rb index 9140fb5db..8b38a911e 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -27,7 +27,7 @@ class Memo < ApplicationRecord scope :hot, -> { order("all_replies_count desc, updated_at desc") } scope :posts, -> { where(root_id: nil, forum_id: [3, 5]) } - validates :content, length: { maximum: 10000 } + validates :content, length: { maximum: 10000, too_long: "帖子内容不能超过10000个字符" } after_create :send_tiding diff --git a/app/models/message.rb b/app/models/message.rb index 7620ef11d..76ea303a9 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -33,7 +33,7 @@ class Message < ApplicationRecord #转发表 # has_many :forwards, as: :from, dependent: :destroy - validates :subject, length: { maximum: 255 } + validates :subject, length: { maximum: 255, too_long: "标题不能超过255个字符" } def update_content(content) message_detail.update_attributes(content: content) diff --git a/app/models/message_detail.rb b/app/models/message_detail.rb index 0d7aaa1c1..9f5269bc5 100644 --- a/app/models/message_detail.rb +++ b/app/models/message_detail.rb @@ -1,5 +1,5 @@ class MessageDetail < ApplicationRecord belongs_to :message, :touch => true - validates :content, length: { maximum: 5000 } + validates :content, length: { maximum: 5000, too_long: "内容不能超过5000个字符" } end diff --git a/app/models/poll.rb b/app/models/poll.rb index 1c38d2426..432bb01d2 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -24,8 +24,8 @@ class Poll < ApplicationRecord scope :poll_search, lambda { |keywords| where("polls_name LIKE ?", "%#{keywords}%") unless keywords.blank?} - validates :polls_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } - validates :polls_description, length: { maximum: 100 } + validates :polls_name, length: { maximum: 60, too_long: "问卷名称不能超过60个字符" } + validates :polls_description, length: { maximum: 100, too_long: "问卷须知不能超过100个字符" } after_create :create_polls_list diff --git a/app/models/poll_answer.rb b/app/models/poll_answer.rb index c7fa7e75c..156be0974 100644 --- a/app/models/poll_answer.rb +++ b/app/models/poll_answer.rb @@ -8,6 +8,6 @@ class PollAnswer < ApplicationRecord scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题 scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 - validates :answer_text, length: { maximum: 500 } + validates :answer_text, length: { maximum: 500, too_long: "选项不能超过500个字符" } end \ No newline at end of file diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index dd7f3f95f..98c1201da 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -9,7 +9,7 @@ class PollQuestion < ApplicationRecord scope :ques_necessary, -> {where("is_necessary = ?",1)} scope :insert_question, lambda {|k| where("question_number > ?",k)} - validates :question_title, length: { maximum: 1000 } + validates :question_title, length: { maximum: 1000, too_long: "题干不能超过1000个字符" } def question_type_name case self.question_type diff --git a/app/models/poll_vote.rb b/app/models/poll_vote.rb index 2e70f1342..440881871 100644 --- a/app/models/poll_vote.rb +++ b/app/models/poll_vote.rb @@ -9,6 +9,6 @@ class PollVote < ApplicationRecord scope :find_current_vote,lambda {|k,v| where("#{k}": v)} scope :find_vote_text,-> {where("vote_text IS NOT NULL")} - validates :vote_text, length: { maximum: 5000 } + validates :vote_text, length: { maximum: 5000, too_long: "内容不能超过5000个字符" } end \ No newline at end of file diff --git a/app/models/shixun_info.rb b/app/models/shixun_info.rb index e3a8d334b..a7da422da 100644 --- a/app/models/shixun_info.rb +++ b/app/models/shixun_info.rb @@ -1,10 +1,10 @@ class ShixunInfo < ApplicationRecord belongs_to :shixun validates_uniqueness_of :shixun_id - validates_length_of :fork_reason, maximum: 60 + validates_length_of :fork_reason, maximum: 60, message: "fork原因不能超过60个字符" after_commit :create_diff_record - validates :description, length: { maximum: 5000 } + validates :description, length: { maximum: 5000, too_long: "简介不能超过5000个字符" } private diff --git a/app/models/shixun_work_comment.rb b/app/models/shixun_work_comment.rb index 1d23718d3..c20f5c509 100644 --- a/app/models/shixun_work_comment.rb +++ b/app/models/shixun_work_comment.rb @@ -2,6 +2,6 @@ class ShixunWorkComment < ApplicationRecord belongs_to :student_work belongs_to :user belongs_to :challenge, optional: true - validates :comment, length: { maximum: 500 } - validates :hidden_comment, length: { maximum: 500 } + validates :comment, length: { maximum: 500, too_long: "评语不能超过500个字符" } + validates :hidden_comment, length: { maximum: 500, too_long: "隐藏评语不能超过500个字符" } end diff --git a/app/models/stage.rb b/app/models/stage.rb index 84873b01f..f6d6b3e56 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -6,6 +6,6 @@ class Stage < ApplicationRecord has_many :stage_shixuns, -> { order("stage_shixuns.position ASC") }, dependent: :destroy has_many :shixuns, :through => :stage_shixuns - validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 1000 } + validates :name, length: { maximum: 60 , too_long: "章节名称不能超过60个字符" } + validates :description, length: { maximum: 1000, too_long: "章节描述不能超过1000个字符" } end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 473efa756..83e6c7b94 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -19,7 +19,7 @@ class StudentWork < ApplicationRecord before_save :set_work_score - validates :description, length: { maximum: 5000 } + validates :description, length: { maximum: 5000, too_long: "描述不能超过5000个字符" } scope :has_committed, lambda { where("work_status != 0") } # 未提交 diff --git a/app/models/student_works_score.rb b/app/models/student_works_score.rb index f9f4f4220..dc8c1451b 100644 --- a/app/models/student_works_score.rb +++ b/app/models/student_works_score.rb @@ -7,7 +7,7 @@ class StudentWorksScore < ApplicationRecord has_many :tidings, as: :container, dependent: :destroy has_many :attachments, as: :container, dependent: :destroy - validates :comment, length: { maximum: 1000 } + validates :comment, length: { maximum: 1000, too_long: "评语不能超过1000个字符" } scope :shixun_comment, lambda { where(is_ultimate: 0) } diff --git a/app/models/subject.rb b/app/models/subject.rb index df9271e5f..459889004 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -31,9 +31,9 @@ class Subject < ApplicationRecord has_many :subject_shixun_infos, dependent: :destroy has_many :subject_user_infos, dependent: :destroy - validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 8000 } - validates :learning_notes, length: { maximum: 2000 } + validates :name, length: { maximum: 60, too_long: "实践课程名称不能超过60个字符" } + validates :description, length: { maximum: 8000, too_long: "实践课程简介不能超过8000个字符" } + validates :learning_notes, length: { maximum: 2000, too_long: "实践课程须知不能超过2000个字符" } scope :visible, lambda{where(status: 2)} scope :published, lambda{where(status: 1)} diff --git a/app/models/test_set.rb b/app/models/test_set.rb index 1fae89afa..f843bfc43 100644 --- a/app/models/test_set.rb +++ b/app/models/test_set.rb @@ -1,7 +1,7 @@ class TestSet < ApplicationRecord # match_rule: 匹配规则: full: 完全匹配, last: 末尾匹配 # - validates :input, length: { maximum: 5000 } - validates :input, length: { maximum: 5000 } + validates :input, length: { maximum: 5000, too_long: "输入不能超过5000个字符" } + validates :output, length: { maximum: 5000, too_long: "输出不能超过5000个字符" } end diff --git a/app/models/trustie_hack.rb b/app/models/trustie_hack.rb index 7c2f3264b..eb2cc06e4 100644 --- a/app/models/trustie_hack.rb +++ b/app/models/trustie_hack.rb @@ -1,5 +1,5 @@ class TrustieHack < ApplicationRecord - validates_length_of :description, maximum: 500 + validates_length_of :description, maximum: 500, message: "描述不能超过500个字符" has_many :hack_users, :dependent => :destroy belongs_to :trustie_hackathon, counter_cache: true