From bb3bee01d20b27908d7d72605b502477318707c9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 26 Nov 2019 14:06:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9E=E8=AE=AD=E5=90=8D?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 12 +++++++++++- app/views/subjects/add_shixun_to_stage.json.jbuilder | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 app/views/subjects/add_shixun_to_stage.json.jbuilder diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index d38293a8f..9ba8bb55d 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -5,7 +5,7 @@ class SubjectsController < ApplicationController before_action :find_subject, except: [:index, :create, :new, :append_to_stage] before_action :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish, :search_members, :add_subject_members, :statistics, :shixun_report, :school_report, - :up_member_position, :down_member_position, :update_team_title] + :up_member_position, :down_member_position, :update_team_title, :add_shixun_to_stage] before_action :require_admin, only: [:copy_subject] include ApplicationHelper @@ -212,6 +212,16 @@ class SubjectsController < ApplicationController @shixuns = Shixun.where(id: params[:shixun_id]).order("id desc") end + # 添加实训项目 + def add_shixun_to_stage + identifier = generate_identifier Shixun, 8 + ActiveRecord::Base.transaction do + @shixun = Shixun.create!(name: params[:name], user_id: current_user.id, identifier: identifier) + # 添加合作者 + @shixun.shixun_members.create!(user_id: current_user.id, role: 1) + end + end + def choose_course course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE m.course_id = c.id AND m.role in (1,2,3) diff --git a/app/views/subjects/add_shixun_to_stage.json.jbuilder b/app/views/subjects/add_shixun_to_stage.json.jbuilder new file mode 100644 index 000000000..45b584231 --- /dev/null +++ b/app/views/subjects/add_shixun_to_stage.json.jbuilder @@ -0,0 +1,3 @@ +json.shixun_identifier @shixun.identifier +json.shixun_name @shixun.name +json.shixun_id @shixun.id \ No newline at end of file