Class: AbsencesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/absences_controller.rb

Constant Summary

Constants included from Localization

Localization::LOCALIZED_STRINGS

Instance Method Summary collapse

Methods inherited from ApplicationController

in_place_edit_for, #initialize, #render_to_string

Methods included from ApplicationHelper

#back_or_link_to, #detour?, #detour_to, #display_notice, #h, #image_button_to, #image_detour_to, #image_link_to, #image_link_to_remote, #insert, #record, #resolution_image, #t, #update_task, #with_detour

Methods included from Localization

#l, load_localized_strings, #valid_language?

Constructor Details

This class inherits a constructor from ApplicationController

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/absences_controller.rb', line 23

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

#destroyObject



64
65
66
67
# File 'app/controllers/absences_controller.rb', line 64

def destroy
  Absence.find(params[:id]).destroy
  redirect_to :action => 'list'
end

#editObject



50
51
52
# File 'app/controllers/absences_controller.rb', line 50

def edit
  @absence = Absence.find(params[:id])
end

#indexObject



2
3
4
5
# File 'app/controllers/absences_controller.rb', line 2

def index
  list
  render :action => 'list'
end

#listObject



11
12
13
# File 'app/controllers/absences_controller.rb', line 11

def list
  @absences = Absence.paginate :per_page => 10, :page => params[:page]
end

#newObject



19
20
21
# File 'app/controllers/absences_controller.rb', line 19

def new
  @absence = Absence.new
end

#showObject



15
16
17
# File 'app/controllers/absences_controller.rb', line 15

def show
  @absence = Absence.find(params[:id])
end

#updateObject



54
55
56
57
58
59
60
61
62
# File 'app/controllers/absences_controller.rb', line 54

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