From 0095202a66bf14d75659d87a2439dc16cd592937 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 20 Aug 2019 11:01:05 +0800 Subject: [PATCH 1/2] tiaoz --- app/controllers/subjects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 431423d87..df6ee31de 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].strip + @search = params[:search].strip if params[:search] @type = params[:type] # 超级管理员用户显示所有未隐藏的实训、非管理员显示合作团队用户的实训(对本单位公开且未隐藏) if current_user.admin? From c497048359ff11b60fa0aff6ea119369438d9bf5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 20 Aug 2019 11:26:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E9=87=91=E8=AF=BE?= =?UTF-8?q?=E6=97=B6=E8=BF=94=E5=9B=9E=E8=AF=BE=E5=A0=82=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 7 ++++++- app/controllers/shixuns_controller.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d97c26127..725c9815b 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -100,7 +100,12 @@ class CoursesController < ApplicationController # GET /courses/new def new @course = Course.new - normal_status("成功") + unless params[:subject_id].blank? + subject = Subject.find_by(id: params[:subject_id], excellent: 1) + render :json => {status: 0, course_name: "#{subject&.name}第#{subject&.courses&.count.to_i + 1}期"} + else + normal_status("成功") + end end # Get /courses/:id/settings diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b9c2086d8..ebc2db1d6 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -564,7 +564,7 @@ class ShixunsController < ApplicationController 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂 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) + subject = Subject.find_by(id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id), excellent: 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!