<commit_before>class CommentsController < ApplicationController

  def new
    @comment = Comment.new
  end

  def create
    if params[:comment][:commentable_type] == 'Question'
      @commentable = Question.find_by(id: params[:comment][:commentable_id])
      @comment = @commentable.comments.create(comment_params)
      render json: {comment: @comment.body}.to_json
    else
      @commentable = Answer.find_by(id: params[:comment][:commentable_id])
      @comment = @commentable.comments.create(comment_params)<commit_msg>Add authentication to comments<commit_after>class CommentsController < ApplicationController
  before_action :require_login, only: [:create]

  def new
    @comment = Comment.new
  end

  def create
    if params[:comment][:commentable_type] == 'Question'
      @commentable = Question.find_by(id: params[:comment][:commentable_id])
      @comment = @commentable.comments.create(comment_params)
      render json: {comment: @comment.body}.to_json
    else
      @commentable = Answer.find_by(id: params[:comment][:commentable_id])
      @comment = @commentable.comments.create(comment_params)
{'fraction_non_alphanumeric': 0.1161751563896336, 'fraction_numerical': 0.0, 'mean_word_length': 4.714285714285714, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7247717', 'n_tokens_mistral': 326, 'n_tokens_neox': 320, 'n_words': 62}