Class: CommentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CommentsController
- 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
-
#create ⇒ Object
POST /comments POST /comments.json.
-
#destroy ⇒ Object
DELETE /comments/1 DELETE /comments/1.json.
-
#edit ⇒ Object
GET /comments/1/edit.
-
#index ⇒ Object
GET /comments GET /comments.json.
-
#new ⇒ Object
GET /comments/new.
-
#show ⇒ Object
GET /comments/1 GET /comments/1.json.
-
#update ⇒ Object
PATCH/PUT /comments/1 PATCH/PUT /comments/1.json.
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
GET /comments/1/edit
33 34 |
# File 'app/controllers/comments_controller.rb', line 33 def edit end |
#index ⇒ Object
GET /comments GET /comments.json
18 19 20 |
# File 'app/controllers/comments_controller.rb', line 18 def index @comments = Comment.all end |
#new ⇒ Object
GET /comments/new
28 29 30 |
# File 'app/controllers/comments_controller.rb', line 28 def new @comment = Comment.new end |
#show ⇒ Object
GET /comments/1 GET /comments/1.json
24 25 |
# File 'app/controllers/comments_controller.rb', line 24 def show end |
#update ⇒ Object
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 |