From 038117953694cae3c78b40cea7034151d07d305f Mon Sep 17 00:00:00 2001 From: yanxd Date: Wed, 20 Nov 2013 17:02:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B7=BB=E5=8A=A0=E8=AE=A8?= =?UTF-8?q?=E8=AE=BA=E5=8C=BA=E5=BD=93=E9=A1=B9=E7=9B=AE=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E6=98=AF=E5=90=A6=E8=83=BD=E5=9B=9E=E5=A4=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=9C=A8=E5=85=A8=E7=BA=BF=E6=8A=A5=E8=A1=A8=E9=87=8C?= =?UTF-8?q?=E9=85=8D=E7=BD=AE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 8 ++------ app/models/project.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ff2d172b..685003c8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -524,17 +524,13 @@ class ProjectsController < ApplicationController @course.extra='course' + DateTime.parse(Time.now.to_s).strftime('%Y-%m-%d_%H-%M-%S').to_s @course.safe_attributes = params[:project][:course] @course.tea_id = User.current.id - # added by bai + # added by bai @course.term = params[:term] @course.time = params[:time] @course.setup_time = params[:setup_time] @course.endup_time = params[:endup_time] @course.class_period = params[:class_period] end - # end - # @course.save - # project = ProjectInfo.create(:user_id => User.current.id, :project_id => @project.id) - # project_status = ProjectStatus.create(:project_id => @project.id) end @issue_custom_fields = IssueCustomField.sorted.all @trackers = Tracker.sorted.all @@ -578,7 +574,7 @@ class ProjectsController < ApplicationController format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => @project.id) } end else - @course.destroy #TODO: yan + @course.destroy respond_to do |format| format.html { render :action => 'new', :layout => 'base'}#Added by young format.api { render_validation_errors(@project) } diff --git a/app/models/project.rb b/app/models/project.rb index bead38ce..730a1060 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -119,6 +119,7 @@ class Project < ActiveRecord::Base after_save :update_position_under_parent, :if => Proc.new {|project| project.name_changed?} after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?} + after_save :create_board_sync #nyan before_destroy :delete_all_members def remove_references_before_destroy return if self.id.nil? @@ -1083,4 +1084,16 @@ class Project < ActiveRecord::Base after_parent_changed(parent_was) end end + + # 创建项目后在项目下同步创建一个讨论区 + def create_board_sync + @board = self.boards.build + @board.name = self.name + @board.description = self.name.to_s << " #{l(:label_board) }" + if @board.save + logger.debug "[Project Model] ===> #{@board.to_json}" + else + logger.error "[Project Model] ===> Auto create board when project saved, because #{@board.full_messages}" + end + end end