新建课程的教师团队为空

This commit is contained in:
cxt 2016-10-08 10:21:33 +08:00
parent b805fdc666
commit 3b8dded2bc
2 changed files with 15 additions and 0 deletions

View File

@ -33,6 +33,8 @@ class SyllabusesController < ApplicationController
@syllabus.user_id = User.current.id
@syllabus.description = Message.where("id = 19412").first.nil? ? '' : Message.where("id = 19412").first.content
if @syllabus && @syllabus.save
member = SyllabusMember.create(:user_id => @syllabus.user_id, :rank => 1)
@syllabus.syllabus_members << member
respond_to do |format|
flash[:notice] = l(:notice_successful_create)
format.html {redirect_to syllabus_path(@syllabus)}

View File

@ -0,0 +1,13 @@
class AddSyllabusMembers < ActiveRecord::Migration
def up
Syllabus.all.each do |syllabus|
if syllabus.syllabus_members.empty?
member = SyllabusMember.create(:user_id => syllabus.user_id, :rank => 1)
syllabus.syllabus_members << member
end
end
end
def down
end
end