cleans up cost_types_controller

pull/6827/head
Jens Ulferts 12 years ago
parent c30b2649a3
commit 1b9a38b203
  1. 46
      app/controllers/cost_types_controller.rb

@ -3,8 +3,7 @@ class CostTypesController < ApplicationController
# Allow only admins here
before_filter :require_admin
before_filter :find_cost_type, :only => [:set_rate, :toggle_delete]
before_filter :find_optional_cost_type, :only => [:edit, :update]
before_filter :find_cost_type, :only => [:edit, :update, :set_rate, :toggle_delete]
helper :sort
include SortHelper
@ -32,38 +31,18 @@ class CostTypesController < ApplicationController
end
def edit
if !@cost_type
@cost_type = CostType.new()
end
@cost_type.attributes = permitted_params.cost_type if params[:cost_type]
if request.post? && @cost_type.save
flash[:notice] = l(:notice_successful_update)
redirect_back_or_default(:action => 'index')
else
@cost_type.rates.build({:valid_from => Date.today}) if @cost_type.rates.empty?
render :action => "edit", :layout => !request.xhr?
end
rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
flash.now[:error] = l(:notice_locking_conflict)
end
def update
# TODO: method is copied over from edit
# remove code as appropriate
if !@cost_type
@cost_type = CostType.new()
end
@cost_type.attributes = permitted_params.cost_type if params[:cost_type]
@cost_type.attributes = permitted_params.cost_type
if @cost_type.save
flash[:notice] = l(:notice_successful_update)
redirect_back_or_default(:action => 'index')
else
@cost_type.rates.build({:valid_from => Date.today}) if @cost_type.rates.empty?
render :action => "edit", :layout => !request.xhr?
end
rescue ActiveRecord::StaleObjectError
@ -74,28 +53,17 @@ class CostTypesController < ApplicationController
def new
# TODO: method is copied over from edit
# remove code as appropriate
if !@cost_type
@cost_type = CostType.new()
end
@cost_type.attributes = permitted_params.cost_type if params[:cost_type]
if request.post? && @cost_type.save
flash[:notice] = l(:notice_successful_update)
redirect_back_or_default(:action => 'index')
else
@cost_type.rates.build({:valid_from => Date.today}) if @cost_type.rates.empty?
render :action => "edit", :layout => !request.xhr?
end
rescue ActiveRecord::StaleObjectError
# Optimistic locking exception
flash.now[:error] = l(:notice_locking_conflict)
end
def create
# TODO: method is copied over from edit
# remove code as appropriate
@cost_type = CostType.new(params[:cost_type])
@cost_type = CostType.new(permitted_params.cost_type)
if @cost_type.save
flash[:notice] = l(:notice_successful_update)
@ -145,12 +113,6 @@ private
render_404
end
def find_optional_cost_type
if !params[:id].blank?
@cost_type = CostType.find(params[:id])
end
end
def default_breadcrumb
l(:caption_cost_type_plural)
end

Loading…
Cancel
Save