From ab59a180c3bc25e08fbbb48afdd652f4b06f1c27 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 20 Aug 2019 10:54:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B=E7=9A=84?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E9=95=BF=E5=BA=A6=E9=99=90=E5=88=B6=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 20 ++++++++++---------- app/controllers/subjects_controller.rb | 4 ++-- app/models/subject.rb | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index c9b56bb98..b9c2086d8 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -562,16 +562,16 @@ class ShixunsController < ApplicationController commit_id = commit["id"] end - # 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂 - # if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) - # subject = Subject.where(excellent: 1, id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id)).take - # course = subject.courses.where("start_date is not null and start_date <= '#{Date.today}' and end_date is not null and end_date >= '#{Date.today}'").take - # if course.present? && !CourseMember.exists?(course_id: course.id, user_id: current_user.id) - # # 为了不影响后续操作,用create而不是create! - # CourseMember.create(course_id: course.id, user_id: current_user.id, role: 4) - # CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) - # end - # end + 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂 + if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) + subject = Subject.where(id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id), excellent: 1).take(1) + course = subject.courses.where("start_date is not null and start_date <= '#{Date.today}' and end_date is not null and end_date >= '#{Date.today}'").take + if course.present? && !CourseMember.exists?(course_id: course.id, user_id: current_user.id) + # 为了不影响后续操作,用create而不是create! + CourseMember.create(course_id: course.id, user_id: current_user.id, role: 4) + CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) + end + end ActiveRecord::Base.transaction do begin diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 5389ff961..431423d87 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -149,7 +149,7 @@ class SubjectsController < ApplicationController end def choose_subject_shixun - @search = params[:search] + @search = params[:search].strip @type = params[:type] # 超级管理员用户显示所有未隐藏的实训、非管理员显示合作团队用户的实训(对本单位公开且未隐藏) if current_user.admin? @@ -163,7 +163,7 @@ class SubjectsController < ApplicationController tag_ids = @shixuns.joins(:shixun_tag_repertoires).pluck(:tag_repertoire_id).uniq @tags = TagRepertoire.select([:id, :name]).where(id: tag_ids) - if params[:search] + unless @search.blank? @shixuns = @shixuns.where("name like ?", "%#{@search}%") end diff --git a/app/models/subject.rb b/app/models/subject.rb index 113460375..5116cce75 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -21,7 +21,7 @@ class Subject < ApplicationRecord # 开放课堂 has_many :courses, -> { order("courses.id ASC") } - validates :name, length: { maximum: 40 } + validates :name, length: { maximum: 60 } validates :description, length: { maximum: 5000 } validates :learning_notes, length: { maximum: 500 }