Sha256: 550091d106acbefed6e17da88c53ed81c67345bd989c437a53458ba35d439637

Contents?: true

Size: 1.5 KB

Versions: 10

Compression:

Stored size: 1.5 KB

Contents

require_dependency "censor_bear/application_controller"

module CensorBear
  class StopWordsController < ApplicationController
    before_action :set_stop_word, only: [:show, :edit, :update, :destroy]

    def index
      load_stop_words
    end

    def show; end

    def new
      @stop_word = StopWord.new
    end

    def edit; end

    def create
      @stop_word = StopWord.new(stop_word_params)
      @stop_word.user = current_user

      if @stop_word.save
        redirect_to @stop_word, notice: 'Stop word was successfully created.'
      else
        render :new
      end
    end

    def update
      if @stop_word.update(stop_word_params)
        redirect_to @stop_word, notice: 'Stop word was successfully updated.'
      else
        render :edit
      end
    end

    def destroy
      @stop_word.destroy

      respond_to do |format|
        format.turbo_stream
        format.html { redirect_to stop_words_url, notice: 'Stop word was successfully destroyed.' }
      end
    end

    def load_stop_words
      builder ||= stop_word_scope
      builder = builder.where("key ilike ?", "%#{params[:q]}%") if params[:q].present?
      builder = builder.order(id: :desc)

      @pagy, @stop_words = pagy(builder)
    end

    private

    def set_stop_word
      @stop_word = StopWord.find(params[:id])
    end

    def stop_word_scope
      StopWord
    end

    def stop_word_params
      params.require(:stop_word).permit(:key, :user_id, :ugc, :username, :signature, :dialog, :nickname, :replacement)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
censor_bear-0.1.12 app/controllers/censor_bear/stop_words_controller.rb
censor_bear-0.1.11 app/controllers/censor_bear/stop_words_controller.rb
censor_bear-0.1.10 app/controllers/censor_bear/stop_words_controller.rb
censor_bear-0.1.9 app/controllers/censor_bear/stop_words_controller.rb
censor_bear-0.1.8 app/controllers/censor_bear/stop_words_controller.rb
censor_bear-0.1.7 app/controllers/censor_bear/stop_words_controller.rb
censor_bear-0.1.6 app/controllers/censor_bear/stop_words_controller.rb
censor_bear-0.1.5 app/controllers/censor_bear/stop_words_controller.rb
censor_bear-0.1.4 app/controllers/censor_bear/stop_words_controller.rb
censor_bear-0.1.3 app/controllers/censor_bear/stop_words_controller.rb