From 814233d245fec3705e879a7d77ae872bc5829931 Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 12 Jun 2014 09:23:44 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E8=AF=BE=E7=A8=8B=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E4=BF=9D=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/news_controller.rb | 35 +++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index e7c39387e..cfa1b6bba 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -102,16 +102,31 @@ class NewsController < ApplicationController end def create - @news = News.new(:project => @project, :author => User.current) - @news.safe_attributes = params[:news] - @news.save_attachments(params[:attachments]) - if @news.save - render_attachment_warning_if_needed(@news) - flash[:notice] = l(:notice_successful_create) - redirect_to project_news_index_path(@project) - else - layout_file = (@project.project_type == 1) ? 'base_courses' : 'base_projects' - render :action => 'new', :layout => layout_file + #modify by nwb + if @project + @news = News.new(:project => @project, :author => User.current) + @news.safe_attributes = params[:news] + @news.save_attachments(params[:attachments]) + if @news.save + render_attachment_warning_if_needed(@news) + flash[:notice] = l(:notice_successful_create) + redirect_to project_news_index_path(@project) + else + layout_file = (@project.project_type == 1) ? 'base_courses' : 'base_projects' + render :action => 'new', :layout => layout_file + end + elsif @course + @news = News.new(:course => @course, :author => User.current) + @news.safe_attributes = params[:news] + @news.save_attachments(params[:attachments]) + if @news.save + render_attachment_warning_if_needed(@news) + flash[:notice] = l(:notice_successful_create) + redirect_to course_news_index_path(@course) + else + layout_file = 'base_courses' + render :action => 'new', :layout => layout_file + end end end