实践课程的阶段名称限制60个字

dev_forum
cxt 5 years ago
parent fc965a3030
commit 4f8585be42

@ -8,7 +8,7 @@ class CourseSecondCategoriesController < ApplicationController
tip_exception("毕设子目录不能重命名") if @category.category_type == "graduation" tip_exception("毕设子目录不能重命名") if @category.category_type == "graduation"
tip_exception("名称不能为空") if params[:name].blank? tip_exception("名称不能为空") if params[:name].blank?
tip_exception("已存在同名子目录") if @course_module.course_second_categories.exists?(name: params[:name].strip) tip_exception("已存在同名子目录") if @course_module.course_second_categories.exists?(name: params[:name].strip)
@category.update_attributes(name: params[:name].strip) @category.update_attributes!(name: params[:name].strip)
normal_status(0, "更新成功") normal_status(0, "更新成功")
end end

@ -39,10 +39,13 @@ class StagesController < ApplicationController
def update def update
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@stage.update_attributes(stage_params) @stage.update_attributes!(stage_params)
@stage.stage_shixuns.destroy_all
unless params[:shixun_id].blank? unless params[:shixun_id].blank?
params[:shixun_id].each do |shixun_id| new_shixun_ids = params[:shixun_id] - @stage.stage_shixuns.pluck(:shixun_id)
delete_shixun_ids = @stage.stage_shixuns.pluck(:shixun_id) - params[:shixun_id]
@stage.stage_shixuns.where(shixun_id: delete_shixun_ids).destroy_all
new_shixun_ids.each do |shixun_id|
shixun = Shixun.where(id: shixun_id).first shixun = Shixun.where(id: shixun_id).first
@stage.stage_shixuns.create!(subject_id: @subject.id, shixun_id: shixun.id, position: @stage.stage_shixuns.count + 1) if shixun.present? @stage.stage_shixuns.create!(subject_id: @subject.id, shixun_id: shixun.id, position: @stage.stage_shixuns.count + 1) if shixun.present?
end end
@ -50,7 +53,7 @@ class StagesController < ApplicationController
@subject.update_attributes(updated_at: Time.now) @subject.update_attributes(updated_at: Time.now)
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("章节更新失败") tip_exception(e.message)
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
end end

@ -207,7 +207,7 @@ class SubjectsController < ApplicationController
end end
rescue Exception => e rescue Exception => e
uid_logger(e.message) uid_logger(e.message)
tip_exception("发送失败") tip_exception(e.message)
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
end end

@ -6,6 +6,6 @@ class Stage < ApplicationRecord
has_many :stage_shixuns, -> { order("stage_shixuns.position ASC") }, dependent: :destroy has_many :stage_shixuns, -> { order("stage_shixuns.position ASC") }, dependent: :destroy
has_many :shixuns, :through => :stage_shixuns has_many :shixuns, :through => :stage_shixuns
validates :name, length: { maximum: 30 } validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 300 } validates :description, length: { maximum: 300 }
end end

Loading…
Cancel
Save