Sha256: b1ce05fef7e6ef028820a1b2408a0ecb49cb0609f605ce4138ef4009620dcd53

Contents?: true

Size: 1.74 KB

Versions: 15

Compression:

Stored size: 1.74 KB

Contents

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
    @absence_pages, @absences = paginate :absences, :per_page => 10
  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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
backlog-0.28.0 app/controllers/absences_controller.rb
backlog-0.29.0 app/controllers/absences_controller.rb
backlog-0.31.0 app/controllers/absences_controller.rb
backlog-0.30.0 app/controllers/absences_controller.rb
backlog-0.32.0 app/controllers/absences_controller.rb
backlog-0.31.1 app/controllers/absences_controller.rb
backlog-0.33.0 app/controllers/absences_controller.rb
backlog-0.33.1 app/controllers/absences_controller.rb
backlog-0.34.1 app/controllers/absences_controller.rb
backlog-0.34.2 app/controllers/absences_controller.rb
backlog-0.34 app/controllers/absences_controller.rb
backlog-0.35.0 app/controllers/absences_controller.rb
backlog-0.35.2 app/controllers/absences_controller.rb
backlog-0.35.1 app/controllers/absences_controller.rb
backlog-0.35.3 app/controllers/absences_controller.rb