diff app/controllers/news_controller.rb @ 1338:25603efa57b5

Merge from live branch
author Chris Cannam
date Thu, 20 Jun 2013 13:14:14 +0100
parents 433d4f72a19b
children 622f24f53b42
line wrap: on
line diff
--- a/app/controllers/news_controller.rb	Wed Jan 23 13:11:25 2013 +0000
+++ b/app/controllers/news_controller.rb	Thu Jun 20 13:14:14 2013 +0100
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -20,13 +20,14 @@
   model_object News
   before_filter :find_model_object, :except => [:new, :create, :index]
   before_filter :find_project_from_association, :except => [:new, :create, :index]
-  before_filter :find_project, :only => [:new, :create]
+  before_filter :find_project_by_project_id, :only => [:new, :create]
   before_filter :authorize, :except => [:index]
   before_filter :find_optional_project, :only => :index
   accept_rss_auth :index
   accept_api_auth :index
 
   helper :watchers
+  helper :attachments
 
   def index
     case params[:format]
@@ -68,13 +69,13 @@
   def create
     @news = News.new(:project => @project, :author => User.current)
     @news.safe_attributes = params[:news]
-    if request.post?
-      if @news.save
-        flash[:notice] = l(:notice_successful_create)
-        redirect_to :controller => 'news', :action => 'index', :project_id => @project
-      else
-        render :action => 'new'
-      end
+    @news.save_attachments(params[:attachments])
+    if @news.save
+      render_attachment_warning_if_needed(@news)
+      flash[:notice] = l(:notice_successful_create)
+      redirect_to :controller => 'news', :action => 'index', :project_id => @project
+    else
+      render :action => 'new'
     end
   end
 
@@ -83,7 +84,9 @@
 
   def update
     @news.safe_attributes = params[:news]
-    if request.put? and @news.save
+    @news.save_attachments(params[:attachments])
+    if @news.save
+      render_attachment_warning_if_needed(@news)
       flash[:notice] = l(:notice_successful_update)
       redirect_to :action => 'show', :id => @news
     else
@@ -96,12 +99,7 @@
     redirect_to :action => 'index', :project_id => @project
   end
 
-private
-  def find_project
-    @project = Project.find(params[:project_id])
-  rescue ActiveRecord::RecordNotFound
-    render_404
-  end
+  private
 
   def find_optional_project
     return true unless params[:project_id]