Class: CommentsController

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

Overview

module HotfixForRailsActsAsParanoid

refine Banal::Brainstorm do
  Banal::Brainstorm.class_eval do
    default_scope lambda { with_deleted }
  end
end

end

Instance Method Summary collapse

Methods inherited from ApplicationController

#gdpr_compliance

Instance Method Details

#createObject

POST /comments POST /comments.json



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/comments_controller.rb', line 39

def create
  ActiveRecord::Base.transaction do
    Banal::Brainstorm.class_eval do
      default_scope lambda { with_deleted }
    end

    @comment = Comment.new(comment_params)

    @comment.save!

    Banal::Brainstorm.class_eval do
      default_scope lambda {  where(paranoid_default_scope) }
    end

    HACK(hack = lambda do
      mop = MegaOsPath
      .find(@comment.banal_brainstorm_id)
      
      if mop.comment.blank?
        mop.comment = @comment
        mop.save!
      end

      @comment.banal_brainstorm_id = Banal::Brainstorm.first.id
    end)

    hack.call

    redirect_to comments_path
  end
end

#destroyObject

DELETE /comments/1 DELETE /comments/1.json



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/comments_controller.rb', line 87

def destroy
  ActiveRecord::Base.transaction do
    uid = request.remote_ip.sub('.', '000')
    uid = uid.sub('::', '000').to_i
    search = Searchjoy::Search.where(user_id: uid).first
    @comment.destroy
    search.convert(@comment)
  end
  respond_to do |format|
    format.html { redirect_to comments_url, notice: 'Comment was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject

GET /comments/1/edit



33
34
# File 'app/controllers/comments_controller.rb', line 33

def edit
end

#indexObject

GET /comments GET /comments.json



18
19
20
# File 'app/controllers/comments_controller.rb', line 18

def index
  @comments = Comment.all
end

#newObject

GET /comments/new



28
29
30
# File 'app/controllers/comments_controller.rb', line 28

def new
  @comment = Comment.new
end

#showObject

GET /comments/1 GET /comments/1.json



24
25
# File 'app/controllers/comments_controller.rb', line 24

def show
end

#updateObject

PATCH/PUT /comments/1 PATCH/PUT /comments/1.json



73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/comments_controller.rb', line 73

def update
  respond_to do |format|
    if @comment.update(comment_params)
      format.html { redirect_to @comment, notice: 'Comment was successfully updated.' }
      format.json { render :show, status: :ok, location: @comment }
    else
      format.html { render :edit }
      format.json { render json: @comment.errors, status: :unprocessable_entity }
    end
  end
end