Skip to content

Commit 5a04e35

Browse files
committed
Fix comment bug + cleanup
1 parent 56de898 commit 5a04e35

File tree

2 files changed

+8
-41
lines changed

2 files changed

+8
-41
lines changed

app/controllers/comments_controller.rb

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
class CommentsController < ApplicationController
22

3-
before_action :access_required, only: [:new, :edit, :update, :destroy]
4-
before_action :verify_ownership, only: [:edit, :update, :destroy]
5-
before_action :require_admin!, only: [:flag, :index]
3+
before_action :access_required, only: [:update, :destroy]
64
before_action :lookup_comment, only: [:edit, :update, :destroy, :like]
5+
before_action :verify_ownership, only: [:edit, :update, :destroy]
76
before_action :lookup_protip, only: [:create]
87

9-
def index
10-
@comments = Comment.where('created_at > ?', 1.day.ago)
11-
end
12-
13-
def new ; end
14-
15-
def edit ; end
16-
178
def create
189
create_comment_params = params.require(:comment).permit(:comment)
1910

@@ -25,10 +16,10 @@ def create
2516

2617
if @comment.save
2718
record_event('created comment')
28-
format.html { redirect_to protip_path(@comment.commentable) }
19+
format.html { redirect_to protip_path(params[:protip_id]) }
2920
format.json { render json: @comment, status: :created, location: @comment }
3021
else
31-
format.html { redirect_to protip_path(@comment.commentable), error: "could not add your comment. try again" }
22+
format.html { redirect_to protip_path(params[:protip_id]), error: "could not add your comment. try again" }
3223
format.json { render json: @comment.errors, status: :unprocessable_entity }
3324
end
3425
end
@@ -39,10 +30,10 @@ def update
3930

4031
respond_to do |format|
4132
if @comment.update_attributes(update_comment_params)
42-
format.html { redirect_to protip_path(@comment.commentable.try(:public_id)) }
33+
format.html { redirect_to protip_path(params[:protip_id]) }
4334
format.json { head :ok }
4435
else
45-
format.html { redirect_to protip_path(@comment.commentable.try(:public_id)), error: "could not update your comment. try again" }
36+
format.html { redirect_to protip_path(params[:protip_id]), error: "could not update your comment. try again" }
4637
format.json { render json: @comment.errors, status: :unprocessable_entity }
4738
end
4839
end
@@ -70,18 +61,15 @@ def like
7061
private
7162

7263
def lookup_comment
73-
id = params.permit(:id)[:id]
74-
@comment = Comment.find(id)
64+
@comment = Comment.find(params[:id])
7565
lookup_protip
7666
end
7767

7868
def lookup_protip
79-
protip_id = params.permit(:protip_id)[:protip_id]
80-
@protip = Protip.with_public_id(protip_id)
69+
@protip = Protip.find_by_public_id(params[:protip_id])
8170
end
8271

8372
def verify_ownership
84-
lookup_comment
8573
redirect_to(root_url) unless (is_admin? or (@comment && @comment.authored_by?(current_user)))
8674
end
8775
end

app/views/comments/index.html.haml

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)