Sha256: 9942ee7796e0f5bcbb69eee0f1683df20b4b088dc0b46539c5ab2769afe0d1c7

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require_dependency "censor_bear/application_controller"

module CensorBear
  class LogsController < ApplicationController
    before_action :set_log, only: %i[show edit update destroy]

    # GET /logs
    def index
      load_logs
    end

    # GET /logs/1
    def show
    end

    # GET /logs/new
    def new
      @log = Log.new
    end

    # GET /logs/1/edit
    def edit
    end

    # POST /logs
    def create
      @log = Log.new(log_params)

      if @log.save
        redirect_to @log, notice: 'Log was successfully created.'
      else
        render :new
      end
    end

    # PATCH/PUT /logs/1
    def update
      if @log.update(log_params)
        redirect_to @log, notice: 'Log was successfully updated.'
      else
        render :edit
      end
    end

    # DELETE /logs/1
    def destroy
      @log.destroy

      respond_to do |format|
        format.turbo_stream
        format.html { redirect_to logs_url, notice: 'Log was successfully destroyed.' }
      end
    end

    def load_logs
      builder ||= log_scope
      builder = builder.where("original_content ilike ?", "%#{params[:q]}%") if params[:q].present?
      builder = builder.where(stage: params[:stage]) if params[:stage].present?
      builder = builder.order(id: :desc)

      @pagy, @logs = pagy(builder)
    end

    private

    # Use callbacks to share common setup or constraints between actions.
    def set_log
      @log = Log.find(params[:id])
    end

    def log_scope
      Log
    end

    # Only allow a list of trusted parameters through.
    def log_params
      params.require(:log).permit(:original_content, :action, :filtered_content, :mod_words)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
censor_bear-0.1.15 app/controllers/censor_bear/logs_controller.rb
censor_bear-0.1.14 app/controllers/censor_bear/logs_controller.rb