From 3b8dded2bc41cd720d404ea66747825102923e70 Mon Sep 17 00:00:00 2001 From: cxt Date: Sat, 8 Oct 2016 10:21:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E8=AF=BE=E7=A8=8B=E7=9A=84?= =?UTF-8?q?=E6=95=99=E5=B8=88=E5=9B=A2=E9=98=9F=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/syllabuses_controller.rb | 2 ++ db/migrate/20161008015936_add_syllabus_members.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 db/migrate/20161008015936_add_syllabus_members.rb diff --git a/app/controllers/syllabuses_controller.rb b/app/controllers/syllabuses_controller.rb index f0d1254bc..a6b11cfbf 100644 --- a/app/controllers/syllabuses_controller.rb +++ b/app/controllers/syllabuses_controller.rb @@ -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)} diff --git a/db/migrate/20161008015936_add_syllabus_members.rb b/db/migrate/20161008015936_add_syllabus_members.rb new file mode 100644 index 000000000..6c477cd51 --- /dev/null +++ b/db/migrate/20161008015936_add_syllabus_members.rb @@ -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