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

#destroyObject

Alphabetized : )



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

def destroy
  @act = @email_action = Office::EmailAction.find( params[:id] )
  authorize! :delete, @act
  @act.update_attributes({ deleted_at: Time.now })
  flash_notice 'Probably success'
  redirect_to action: :index
end

#editObject



16
17
18
19
20
# File 'app/controllers/ish_manager/email_actions_controller.rb', line 16

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



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

def index
  @email_actions = Office::EmailAction.where({ :deleted_at => nil })

  authorize! :index, @new_email_action
end

#newObject



28
29
30
# File 'app/controllers/ish_manager/email_actions_controller.rb', line 28

def new
  authorize! :new, @new_email_action
end

#showObject



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

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

#updateObject

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



39
40
41
42
43
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
# File 'app/controllers/ish_manager/email_actions_controller.rb', line 39

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