Sha256: 541257ac1eb230f61caeeb3ee95a117b4f8c90a6e748e61594eeef1cf4b79ec7

Contents?: true

Size: 1.69 KB

Versions: 11

Compression:

Stored size: 1.69 KB

Contents

class CommentsController < ApplicationController
  before_action :set_comment, only: [:show, :edit, :update, :destroy]

  # GET /comments
  def index
    @comments = Comment.where(is_approved: true).all
  end

  # GET /comments/1
  def show
  end

  # GET /comments/new
  def new
    @comment = Comment.new
  end

  # GET /comments/1/edit
  def edit
  end

  # POST /comments
  def create
    create_params = comment_params.to_hash.deep_symbolize_keys
    create_params[:content] = CensorBear::StopWord.filter(create_params[:content], 'ugc')

    @comment = Comment.new(create_params)
    @comment.user = current_user

    if @comment.save
      text_data_id = CensorBear::TextDataId.encode(@comment, user_id: @comment.user.id, ip_address: request.ip)
      r = CensorBear::CheckText.new(@comment.content, text_data_id, "ugc").scan

      if r.review
        @comment.update_columns(is_approved: false)
      end

      redirect_to @comment, notice: "Comment was successfully created."
    else
      render :new
    end
  end

  # PATCH/PUT /comments/1
  def update
    update_params = comment_params.to_hash.deep_symbolize_keys

    if @comment.update(update_params)
      redirect_to @comment, notice: "Comment was successfully updated."
    else
      render :edit
    end
  end

  # DELETE /comments/1
  def destroy
    @comment.destroy
    redirect_to comments_url, notice: "Comment was successfully destroyed."
  end

  private

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

  # Only allow a list of trusted parameters through.
  def comment_params
    params.require(:comment).permit(:content, :user_id, :is_approved)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
censor_bear-0.1.29 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.28 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.27 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.26 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.25 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.24 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.23 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.22 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.21 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.20 test/dummy/app/controllers/comments_controller.rb
censor_bear-0.1.19 test/dummy/app/controllers/comments_controller.rb