Sha256: 24211ebebd627ab35d5225d4688e6b99daa198b1276a52d1d7134798eebcd3f4

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module SolidErrors
  class ErrorsController < ApplicationController
    around_action :force_english_locale!

    before_action :set_error, only: %i[show update]

    # GET /errors
    def index
      errors_table = Error.arel_table
      occurrences_table = Occurrence.arel_table

      @errors = Error.unresolved
        .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

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

    # PATCH/PUT /errors/1
    def update
      @error.update!(error_params)
      redirect_to errors_path, notice: "Error marked as resolved."
    end

    private

    # Only allow a list of trusted parameters through.
    def error_params
      params.require(:error).permit(:resolved_at)
    end

    def set_error
      @error = Error.find(params[:id])
    end

    def force_english_locale!(&action)
      I18n.with_locale(:en, &action)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solid_errors-0.4.3 app/controllers/solid_errors/errors_controller.rb