Class: KablamController

Inherits:
ApplicationController
  • Object
show all
Includes:
Concerns::ApiSettings
Defined in:
app/controllers/kablam_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/kablam_controller.rb', line 34

def create
  @object = @model.new(model_params)

  if @object.save
    slack?(:create)
    redirect_to params[:redirect] if params[:redirect].present?
    respond_to do |format|
      format.js
      format.html do
        redirect_to request.referrer
        flash[:notice] = :Created
      end
    end
  else
    # TODO: Add some failure handling 👍
  end
end

#destroyObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/kablam_controller.rb', line 68

def destroy
  if @object.destroy
    slack?(:destroy)
    redirect_to params[:redirect] if params[:redirect].present?
    respond_to do |format|
      format.js
      format.html do
        redirect_to request.referrer
        flash[:notice] = :Destroyed
      end
    end
  else
    # TODO: Add some failure handling 👍
  end
end

#formObject



12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/kablam_controller.rb', line 12

def form
  # Automatically Render Vanilla Form for use w/ JS.load
  if params[:id].present?
    set_object
  else
    @object = @model.new
    set_ref
  end
  render layout: false
end

#messageObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/kablam_controller.rb', line 23

def message
  @message = JSON.parse(params[:message])
  redirect_to params[:redirect] if params[:redirect].present?
  respond_to do |format|
    format.js
    format.html do
      redirect_to request.referrer
    end
  end
end

#slackObject



88
89
90
# File 'app/controllers/kablam_controller.rb', line 88

def slack
  render status: 200, json: params['challenge']
end

#undoObject



84
85
86
# File 'app/controllers/kablam_controller.rb', line 84

def undo
  @object.update(undo_params)
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/kablam_controller.rb', line 52

def update
  if @object.update(model_params)
    slack?(:update)
    redirect_to params[:redirect] if params[:redirect].present?
    respond_to do |format|
      format.js
      format.html do
        redirect_to request.referrer
        flash[:notice] = :Updated
      end
    end
  else
    # ADD FAILURE HANDLING
  end
end