class WorkAccountsController < ApplicationController def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def list @work_accounts = WorkAccount.paginate :page => params[:page], :order => 'name' end def show @work_account = WorkAccount.find(params[:id]) works = @work_account.works.select{|w|w.user_id == current_user.id} @backlog_totals = works.to_summarized_hash {|work| [work.task && work.task.backlog, work.hours]} @task_totals = works.to_summarized_hash {|work| [work.task, work.hours]} @task_totals_per_backlog = @task_totals.to_a.to_grouped_hash {|task, hours| [task && task.backlog, [task, hours]]} @total_hours = works.inject(BigDecimal('0')) {|total, work| total += work.hours} end def new @work_account = WorkAccount.new end def create @work_account = WorkAccount.new(params[:work_account]) if @work_account.save flash[:notice] = 'WorkAccount was successfully created.' redirect_to :action => 'list' else render :action => 'new' end end def edit @work_account = WorkAccount.find(params[:id]) end def update @work_account = WorkAccount.find(params[:id]) if @work_account.update_attributes(params[:work_account]) flash[:notice] = 'WorkAccount was successfully updated.' back_or_redirect_to :action => 'show', :id => @work_account else render :action => 'edit' end end def destroy WorkAccount.find(params[:id]).destroy redirect_to :action => 'list' end end