class AbsencesController < 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 @absences = Absence.paginate :per_page => 10, :page => params[:page] end def show @absence = Absence.find(params[:id]) end def new @absence = Absence.new end def create @absence = Absence.find(:first, :conditions => {:on => params[:absence][:on], :user_id => current_user.id}) if @absence if params[:absence][:reason] == '' @absence.destroy flash[:notice] = 'Absence was successfully destroyed.' else @absence.update_attributes(params[:absence]) flash[:notice] = 'Absence was successfully updated.' end back_or_redirect_to :action => 'list' else if params[:absence][:reason] == '' back_or_redirect_to :action => 'list' return end @absence = Absence.new(params[:absence]) @absence.user_id = current_user.id if @absence.save flash[:notice] = 'Absence was successfully created.' back_or_redirect_to :action => 'list' else render :action => 'new' end end end def edit @absence = Absence.find(params[:id]) end def update @absence = Absence.find(params[:id]) if @absence.update_attributes(params[:absence]) flash[:notice] = 'Absence was successfully updated.' redirect_to :action => 'show', :id => @absence else render :action => 'edit' end end def destroy Absence.find(params[:id]).destroy redirect_to :action => 'list' end end