diff app/controllers/custom_fields_controller.rb @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
line wrap: on
line diff
--- a/app/controllers/custom_fields_controller.rb	Fri Jun 14 09:07:32 2013 +0100
+++ b/app/controllers/custom_fields_controller.rb	Fri Jun 14 09:28:30 2013 +0100
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2012  Jean-Philippe Lang
+# Copyright (C) 2006-2013  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
@@ -23,7 +23,7 @@
   before_filter :find_custom_field, :only => [:edit, :update, :destroy]
 
   def index
-    @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name }
+    @custom_fields_by_type = CustomField.all.group_by {|f| f.class.name }
     @tab = params[:tab] || 'IssueCustomField'
   end
 
@@ -31,10 +31,10 @@
   end
 
   def create
-    if request.post? and @custom_field.save
+    if @custom_field.save
       flash[:notice] = l(:notice_successful_create)
       call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
-      redirect_to :action => 'index', :tab => @custom_field.class.name
+      redirect_to custom_fields_path(:tab => @custom_field.class.name)
     else
       render :action => 'new'
     end
@@ -44,21 +44,22 @@
   end
 
   def update
-    if request.put? and @custom_field.update_attributes(params[:custom_field])
+    if @custom_field.update_attributes(params[:custom_field])
       flash[:notice] = l(:notice_successful_update)
       call_hook(:controller_custom_fields_edit_after_save, :params => params, :custom_field => @custom_field)
-      redirect_to :action => 'index', :tab => @custom_field.class.name
+      redirect_to custom_fields_path(:tab => @custom_field.class.name)
     else
       render :action => 'edit'
     end
   end
 
   def destroy
-    @custom_field.destroy
-    redirect_to :action => 'index', :tab => @custom_field.class.name
-  rescue
-    flash[:error] = l(:error_can_not_delete_custom_field)
-    redirect_to :action => 'index'
+    begin
+      @custom_field.destroy
+    rescue
+      flash[:error] = l(:error_can_not_delete_custom_field)
+    end
+    redirect_to custom_fields_path(:tab => @custom_field.class.name)
   end
 
   private
@@ -67,6 +68,8 @@
     @custom_field = CustomField.new_subclass_instance(params[:type], params[:custom_field])
     if @custom_field.nil?
       render_404
+    else
+      @custom_field.default_value = nil
     end
   end