Class: IshManager::OfficeActionsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#basic_auth, #home, #tinymce

Instance Method Details

#createObject

Alphabetized : )



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/ish_manager/office_actions_controller.rb', line 8

def create
  @new_office_action = Office::Action.new params[:office_action].permit!
  authorize! :create, @new_office_action
  flag = @new_office_action.save
  if flag
    flash[:notice] = "Created OAction."
    redirect_to action: 'index'
  else
    flash[:alert] = "Cannot create OAction: #{@new_office_action.errors.full_messages.join(', ')}."
    render action: 'new'
  end
end

#editObject



21
22
23
24
25
# File 'app/controllers/ish_manager/office_actions_controller.rb', line 21

def edit
  @act = @office_action = Office::Action.find( params[:id] )
  @act.ties.push Office::ActionTie.new( next_office_action_id: nil )
  authorize! :edit, @act
end

#indexObject



27
28
29
30
31
# File 'app/controllers/ish_manager/office_actions_controller.rb', line 27

def index
  @office_actions = Office::Action.all

  authorize! :index, @new_office_action
end

#newObject



33
34
35
# File 'app/controllers/ish_manager/office_actions_controller.rb', line 33

def new
  authorize! :new, @new_office_action
end

#showObject



37
38
39
40
# File 'app/controllers/ish_manager/office_actions_controller.rb', line 37

def show
  @act = @office_action = Office::Action.find( params[:id] )
  authorize! :show, @act
end

#updateObject

def create; update; end def upsert; update; end



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/ish_manager/office_actions_controller.rb', line 44

def update
  if params[:id]
    @act = @office_action = Office::Action.find( params[:id] )
  else
    @act = @office_action = Office::Action.new
  end
  authorize! :upsert, @act

  if params[:office_action][:ties_attributes]
    params[:office_action][:ties_attributes].each do |k, v|
      if !v[:next_office_action_id].present?
        params[:office_action][:ties_attributes].delete( k )
      end
      if v[:to_delete] == "1"
        EActie.find( v[:id] ).delete
        params[:office_action][:ties_attributes].delete( k )
      end
    end
  end

  flag = @act.update_attributes( params[:office_action].permit! )
  if flag
    flash[:notice] = 'Success'
    redirect_to action: 'index'
  else
    flash[:alert] = "No luck: #{@act.errors.full_messages.join(', ')}. #{@act.ties.map { |t| t.errors.full_messages.join(', ') }.join(' | ') }"
    render action: 'edit'
  end

end