<commit_before>class CommentsController < ApplicationController

  def new
    if params[:question_id]
      @commentable = Question.find_by(id: params[:question_id])
    else
      @commentable = Answer.find_by(id: params[:answer_id])
    end
      @comment = @commentable.comments.new
  end

  def create
    if params[:question_id]
      question = Question.find_by(id: params[:question_id])
      @comment = question.comments.new(user: current_user, content: params[:comment][:content])
    else
      answer = Answer.find_by(id: params[:answer_id])
      @comment = answer.comments.new(user: current_user, content: params[:comment][:content])
    end
    if @comment.save
      if @comment.commentable_type == Question
        redirect_to question_path(id: @comment.commentable_id)
      else
        redirect_to question_path(id: @comment.commentable.question_id)
      end
    else
      render :new
    end
  end

  def edit
    @comment = Comment.find_by(id: params[:id])
    @question = Question.find_by(id: @comment.commentable_id)
  end

  def update
    @comment = Comment.find_by(id: params[:id])
    if @comment.update_attributes(comment_params)
      redirect_to question_path(id: @comment.commentable_id)
    else
      render :edit
    end
  end<commit_msg>Fix bug with answer comments in comments#update<commit_after>class CommentsController < ApplicationController

  def new
    if params[:question_id]
      @commentable = Question.find_by(id: params[:question_id])
    else
      @commentable = Answer.find_by(id: params[:answer_id])
    end
      @comment = @commentable.comments.new
  end

  def create
    if params[:question_id]
      question = Question.find_by(id: params[:question_id])
      @comment = question.comments.new(user: current_user, content: params[:comment][:content])
    else
      answer = Answer.find_by(id: params[:answer_id])
      @comment = answer.comments.new(user: current_user, content: params[:comment][:content])
    end
    if @comment.save
      if @comment.commentable_type == "Question"
        redirect_to question_path(id: @comment.commentable_id)
      else
        redirect_to question_path(id: @comment.commentable.question_id)
      end
    else
      render :new
    end
  end

  def edit
    @comment = Comment.find_by(id: params[:id])
    @question = Question.find_by(id: @comment.commentable_id)
  end

  def update
    @comment = Comment.find_by(id: params[:id])
    if @comment.update_attributes(comment_params)
      if @comment.commentable_type == "Question"
        redirect_to question_path(id: @comment.commentable_id)
      else
        redirect_to question_path(id: @comment.commentable.question_id)
      end
    else
      render :edit
    end
  end
{'fraction_non_alphanumeric': 0.10293040293040293, 'fraction_numerical': 0.0, 'mean_word_length': 3.3836276083467096, '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': '122527', 'n_tokens_mistral': 834, 'n_tokens_neox': 825, 'n_words': 177}