Byte4/acebook-byte4

View on GitHub
app/controllers/comments_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
Missing top-level class documentation comment.
Missing magic comment `# frozen_string_literal: true`.
class CommentsController < ApplicationController
Extra empty line detected at class body beginning.
 
before_action :set_post
 
def create
@comment = @post.comments.build(comment_params)
@comment.user_id = current_user.id
 
if @comment.save
respond_to do |format|
format.html { redirect_to authenticate_root_path }
format.js
end
else
render authenticate_root_path
end
end
 
def destroy
@comment = @post.comments.find(params[:id])
 
Use a guard clause instead of wrapping the code inside a conditional expression.
if @comment.user_id == current_user.id
@comment.destroy
respond_to do |format|
Space missing inside }.
format.html { redirect_to authenticate_root_path}
format.js
end
end
end
 
private
 
def comment_params
params.require(:comment).permit(:content)
end
 
def set_post
@post = Post.find(params[:post_id])
end
Extra empty line detected at class body end.
 
end