Class: AlertsController

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

Constant Summary

Constants inherited from ApplicationController

ApplicationController::ALLOWABLE_CONFIGS

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/alerts_controller.rb', line 17

def create
  respond_to do |format|
    format.json do
      alert = Alert.create(alert_params)

      if alert.errors.any?
        render json: alert.errors.full_messages, status: :unprocessable_entity
      else
        alert.run
        render json: alert, status: :created
      end
    end
  end
end

#destroyObject



54
55
56
57
58
59
60
61
# File 'app/controllers/alerts_controller.rb', line 54

def destroy
  respond_to do |format|
    format.json do
      @alert.destroy!
      render json: @alert
    end
  end
end

#indexObject



7
8
9
10
11
12
13
14
15
# File 'app/controllers/alerts_controller.rb', line 7

def index
  respond_to do |format|
    format.html
    format.json do
      @paginated_alerts = Alert.paginated(@alerts, alert_pagination_params)
      render json: @paginated_alerts
    end
  end
end

#showObject



47
48
49
50
51
52
# File 'app/controllers/alerts_controller.rb', line 47

def show
  respond_to do |format|
    format.json { render json: @alert }
    format.html { render template: 'application/index' }
  end
end

#updateObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/alerts_controller.rb', line 32

def update
  respond_to do |format|
    format.json do
      @alert.update_attributes!(alert_params)

      if @alert.errors.any?
        render json: @alert.errors.full_messages, status: :unprocessable_entity
      else
        @alert.run
        render json: @alert, status: :created
      end
    end
  end
end