summaryrefslogtreecommitdiffstats
path: root/app/controllers/enumerations_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-12-11 10:26:12 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-12-11 10:26:12 +0000
commit0471de41ff4828345ca0afa393f4b8f3bf0098d2 (patch)
treeba8c101be1d1d5adda486d06f32836d5ed59e041 /app/controllers/enumerations_controller.rb
parent1ad16c2238be1b1e0cc29435203b8fd8c233a85c (diff)
downloadredmine-0471de41ff4828345ca0afa393f4b8f3bf0098d2.tar.gz
redmine-0471de41ff4828345ca0afa393f4b8f3bf0098d2.zip
Resourcified enumerations.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8189 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/enumerations_controller.rb')
-rw-r--r--app/controllers/enumerations_controller.rb43
1 files changed, 22 insertions, 21 deletions
diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb
index c567b6ae6..f2777c3c6 100644
--- a/app/controllers/enumerations_controller.rb
+++ b/app/controllers/enumerations_controller.rb
@@ -19,28 +19,19 @@ class EnumerationsController < ApplicationController
layout 'admin'
before_filter :require_admin
+ before_filter :build_new_enumeration, :only => [:new, :create]
+ before_filter :find_enumeration, :only => [:edit, :update, :destroy]
helper :custom_fields
- include CustomFieldsHelper
def index
end
- verify :method => :post, :only => [ :destroy, :create, :update ],
- :redirect_to => { :action => :index }
-
def new
- begin
- @enumeration = params[:type].constantize.new
- rescue NameError
- @enumeration = Enumeration.new
- end
end
def create
- @enumeration = Enumeration.new(params[:enumeration])
- @enumeration.type = params[:enumeration][:type]
- if @enumeration.save
+ if request.post? && @enumeration.save
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'index', :type => @enumeration.type
else
@@ -49,13 +40,10 @@ class EnumerationsController < ApplicationController
end
def edit
- @enumeration = Enumeration.find(params[:id])
end
def update
- @enumeration = Enumeration.find(params[:id])
- @enumeration.type = params[:enumeration][:type] if params[:enumeration][:type]
- if @enumeration.update_attributes(params[:enumeration])
+ if request.put? && @enumeration.update_attributes(params[:enumeration])
flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'index', :type => @enumeration.type
else
@@ -63,8 +51,8 @@ class EnumerationsController < ApplicationController
end
end
+ verify :method => :delete, :only => :destroy, :render => { :nothing => true, :status => :method_not_allowed }
def destroy
- @enumeration = Enumeration.find(params[:id])
if !@enumeration.in_use?
# No associated objects
@enumeration.destroy
@@ -77,9 +65,22 @@ class EnumerationsController < ApplicationController
return
end
end
- @enumerations = @enumeration.class.find(:all) - [@enumeration]
- #rescue
- # flash[:error] = 'Unable to delete enumeration'
- # redirect_to :action => 'index'
+ @enumerations = @enumeration.class.all - [@enumeration]
+ end
+
+ private
+
+ def build_new_enumeration
+ class_name = params[:enumeration] && params[:enumeration][:type] || params[:type]
+ @enumeration = Enumeration.new_subclass_instance(class_name, params[:enumeration])
+ if @enumeration.nil?
+ render_404
+ end
+ end
+
+ def find_enumeration
+ @enumeration = Enumeration.find(params[:id])
+ rescue ActiveRecord::RecordNotFound
+ render_404
end
end