codemy/writefully

View on GitHub
app/controllers/comments_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
class CommentsController < ApplicationController
  def create
    @post = Post.where(id: params[:post_id]).first
    @comment = @post.comments.build(comment_params)
    @comment.user = current_user
    if @comment.save
      redirect_to post_path(@post)
    else
      # error handling
    end
  end
private

  def comment_params
    params.require(:comment).permit(:body)
  end
end