在线学习

dev_cs
cxt 5 years ago
parent baba6aa9e9
commit 4f503270aa

@ -166,6 +166,8 @@ class CoursesController < ApplicationController
end end
Inform.create(container: @course, description: @subject.learning_notes, name: "学习须知") Inform.create(container: @course, description: @subject.learning_notes, name: "学习须知")
@course.create_stages @course.subject
end end
course_module_types = params[:course_module_types] course_module_types = params[:course_module_types]

@ -333,6 +333,17 @@ class Course < ApplicationRecord
teacher_power_courses teacher_power_courses
end end
def create_stages subject
if subject
subject.stages.each do |stage|
new_stage = CourseStage.create!(course_id: id, name: stage.name, description: stage.description, position: stage.position)
stage.stage_shixuns.each do |stage_shixun|
CourseStageShixun.create!(course_id: id, course_stage_id: new_stage.id, shixun_id: stage_shixun.shixun_id, position: stage_shixun.position)
end
end
end
end
private private
#创建课程后,给该用户发送消息 #创建课程后,给该用户发送消息

@ -1,5 +1,5 @@
class CourseStage < ApplicationRecord class CourseStage < ApplicationRecord
belongs_to :course, counter_cache: true belongs_to :course
has_many :course_stage_shixuns, -> { order("course_stage_shixuns.position ASC") }, dependent: :destroy has_many :course_stage_shixuns, -> { order("course_stage_shixuns.position ASC") }, dependent: :destroy
has_many :shixuns, :through => :course_stage_shixuns has_many :shixuns, :through => :course_stage_shixuns

@ -1,5 +1,5 @@
class CourseStageShixun < ApplicationRecord class CourseStageShixun < ApplicationRecord
belongs_to :course, counter_cache: :stages_count, counter_cache: :shixuns_count belongs_to :course
belongs_to :course_stage belongs_to :course_stage, counter_cache: :shixuns_count
belongs_to :shixun, counter_cache: :shixuns_count belongs_to :shixun
end end

@ -0,0 +1,14 @@
class MigrateCourseStages < ActiveRecord::Migration[5.2]
def change
Course.where(excellent: 1).each do |course|
if course.subject
course.subject.stages.each do |stage|
new_stage = CourseStage.create!(course_id: course.id, name: stage.name, description: stage.description, position: stage.position)
stage.stage_shixuns.each do |stage_shixun|
CourseStageShixun.create!(course_id: course.id, course_stage_id: new_stage.id, shixun_id: stage_shixun.shixun_id, position: stage_shixun.position)
end
end
end
end
end
end
Loading…
Cancel
Save