Class: WcoEmail::MessageStubsController

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

Instance Method Summary collapse

Instance Method Details

#churnObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 4

def churn
  @stub = WcoEmail::MessageStub.find params[:id]
  authorize! :churn, @stub

  # WcoEmail::MessageIntakeJob.perform_async( @stub.id.to_s )
  begin
    @stub.do_process
  rescue => err
    @stub.update({ status: WcoEmail::MessageStub::STATUS_FAILED })
    puts! err, "WcoEmail::MessageIntakeJob error"
    ::ExceptionNotifier.notify_exception(
      err,
      data: { stub: @stub }
    )
  end

  flash_notice "Churned 1 stub."
  redirect_to request.referrer
end

#createObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 24

def create
  @stub = WcoEmail::MessageStub.new params[:stub].permit!
  authorize! :create, @stub
  if @stub.save
    flash_notice 'saved.'
    redirect_to action: 'show'
  else
    flash_alert "Cannot save stub: #{@stub.errors.full_messages}"
    render 'new'
  end
end

#editObject



36
37
38
39
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 36

def edit
  @stub = WcoEmail::MessageStub.find params[:id]
  authorize! :edit, @stub
end

#indexObject



41
42
43
44
45
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 41

def index
  authorize! :index, WcoEmail::MessageStub
  @stubs = WcoEmail::MessageStub.all.page( params[:stubs_page] )
  render '_index_table'
end

#newObject



47
48
49
50
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 47

def new
  @stub = WcoEmail::MessageStub.new
  authorize! :new, @stub
end

#showObject



52
53
54
55
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 52

def show
  @stub = WcoEmail::MessageStub.find params[:id]
  authorize! :show, @stub
end

#updateObject



57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/wco_email/message_stubs_controller.rb', line 57

def update
  @stub = WcoEmail::MessageStub.find params[:id]
  authorize! :update, @stub
  flag = @stub.update_attributes params[:stub].permit!
  if flag
    flash_notice 'success'
    redirect_to action: 'show'
  else
    flash_alert "Cannot save stub: #{@stub.errors.full_messages}"
    render 'edit'
  end
end