Class: IshManager::EmailActionsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#basic_auth, #home, #tinymce

Instance Method Details

#editObject

Alphabetized : )



8
9
10
11
12
# File 'app/controllers/ish_manager/email_actions_controller.rb', line 8

def edit
  @act = @email_action = Office::EmailAction.find( params[:id] )
  @act.ties.push Office::EmailActionTie.new( next_email_action_id: nil )
  authorize! :edit, @act
end

#indexObject



14
15
16
17
18
# File 'app/controllers/ish_manager/email_actions_controller.rb', line 14

def index
  @email_actions = Office::EmailAction.all

  authorize! :index, @new_email_action
end

#newObject



20
21
22
# File 'app/controllers/ish_manager/email_actions_controller.rb', line 20

def new
  authorize! :new, @new_email_action
end

#showObject



24
25
26
27
# File 'app/controllers/ish_manager/email_actions_controller.rb', line 24

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

#updateObject

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/ish_manager/email_actions_controller.rb', line 31

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

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

  flag = @act.update_attributes( params[:email_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