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

#choose_layout

Instance Method Details

#createObject

POST /comments POST /comments.json



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/comments_controller.rb', line 38

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

    redirect_to banal_brainstorms_path
  end
end

#destroyObject

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



72
73
74
75
76
77
78
# File 'app/controllers/comments_controller.rb', line 72

def destroy
  @comment.destroy
  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



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

def edit
end

#indexObject

GET /comments GET /comments.json



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

def index
  @comments = Comment.all
end

#newObject

GET /comments/new



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

def new
  @comment = Comment.new
end

#showObject

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



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

def show
end

#updateObject

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



58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/comments_controller.rb', line 58

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