From 48295a6c4b9ac47263631b653153743b43afdf66 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 17 Jan 2009 08:41:30 +0000 Subject: CustomFieldsController refactoring. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2273 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/custom_fields_controller.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb index 9b13d19b6..c9f798f5f 100644 --- a/app/controllers/custom_fields_controller.rb +++ b/app/controllers/custom_fields_controller.rb @@ -30,19 +30,14 @@ class CustomFieldsController < ApplicationController end def new - case params[:type] - when "IssueCustomField" - @custom_field = IssueCustomField.new(params[:custom_field]) - when "UserCustomField" - @custom_field = UserCustomField.new(params[:custom_field]) - when "ProjectCustomField" - @custom_field = ProjectCustomField.new(params[:custom_field]) - when "TimeEntryCustomField" - @custom_field = TimeEntryCustomField.new(params[:custom_field]) - else - redirect_to :action => 'list' - return - end + @custom_field = begin + if params[:type].to_s.match(/.+CustomField$/) + params[:type].to_s.constantize.new(params[:custom_field]) + end + rescue + end + redirect_to(:action => 'list') and return unless @custom_field.is_a?(CustomField) + if request.post? and @custom_field.save flash[:notice] = l(:notice_successful_create) redirect_to :action => 'list', :tab => @custom_field.class.name -- cgit v1.2.3