Class: SolidErrors::ErrorsController

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

Constant Summary

Constants inherited from ApplicationController

ApplicationController::OverflowError

Instance Method Summary collapse

Instance Method Details

#destroyObject

DELETE /errors/1



36
37
38
39
40
41
42
43
# File 'app/controllers/solid_errors/errors_controller.rb', line 36

def destroy
  if @error.resolved?
    @error.destroy
    redirect_to errors_path(scope: :resolved), notice: "Error deleted."
  else
    redirect_to error_path(@error), alert: "You must resolve the error before deleting it."
  end
end

#indexObject

GET /errors



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

def index
  errors_table = Error.arel_table
  occurrences_table = Occurrence.arel_table
  query_scope = error_scope.resolved? ? Error.resolved : Error.unresolved
  @errors = query_scope
    .joins(:occurrences)
    .select(errors_table[Arel.star],
      occurrences_table[:created_at].maximum.as("recent_occurrence"),
      occurrences_table[:id].count.as("occurrences_count"))
    .group(errors_table[:id])
    .order(recent_occurrence: :desc)
end

#showObject

GET /errors/1



24
25
26
27
# File 'app/controllers/solid_errors/errors_controller.rb', line 24

def show
  @page = Page.new(@error.occurrences, params)
  @occurrences = @error.occurrences.offset(@page.offset).limit(@page.items).order(created_at: :desc)
end

#updateObject

PATCH/PUT /errors/1



30
31
32
33
# File 'app/controllers/solid_errors/errors_controller.rb', line 30

def update
  @error.update!(error_params)
  redirect_to errors_path, notice: "Error marked as resolved."
end