<commit_before>class AnswersController < ApplicationController
  include Voted

  before_action :authenticate_user!, only: [:create, :edit, :update, :destroy, :accept]
  before_action :set_question, only: [:create]
  before_action :set_answer, only: [:edit, :update, :destroy, :accept]

  after_action :publish_answer, only: [:create]

  def edit
  end

  def create
    @answer = @question.answers.new(answer_params)
    @answer.user = current_user

    @answer.save
  end

  def update
    @answer.update(answer_params) if current_user.author_of?(@answer)
  end

  def destroy
    @answer.destroy if current_user.author_of?(@answer)
    @question = @answer.question
  end

  def accept
    @answer.accept if current_user.author_of?(@answer.question)
  end

  private

  def publish_answer
    return if @answer.errors.any?

    attachments = []
    @answer.attachments.each { |a| attachments << {id: a.id, file_url: a.file.url, file_name: a.file.identifier} }

    data = {
      answer:             @answer,
      answer_user_id:     current_user.id,
      question_user_id:   @question.user_id,
      answer_rating:      @answer.rating,<commit_msg>Refact answers controller with responders<commit_after>class AnswersController < ApplicationController
  include Voted

  before_action :authenticate_user!, only: [:create, :edit, :update, :destroy, :accept]
  before_action :set_question, only: [:create]
  before_action :set_answer, only: [:edit, :update, :destroy, :accept]

  after_action :publish_answer, only: [:create]

  respond_to :js

  def create
    @answer = current_user.answers.create(answer_params.merge(question_id: @question.id))
    respond_with(@answer)
  end

  def update
    @answer.update(answer_params) if current_user.author_of?(@answer)
  end

  def destroy
    @question = @answer.question
    respond_with(@answer.destroy) if current_user.author_of?(@answer)
  end

  def accept
    respond_with(@answer.accept) if current_user.author_of?(@answer.question)
  end

  private

  def publish_answer
    return if @answer.errors.any?

    attachments = []
    @answer.attachments.each { |a| attachments << {id: a.id, file_url: a.file.url, file_name: a.file.identifier} }

    data = {
      answer:             @answer,
      answer_user_id:     current_user.id,
      question_user_id:   @question.user_id,
      answer_rating:      @answer.rating,
{'fraction_non_alphanumeric': 0.11031578947368421, 'fraction_numerical': 0.0, 'mean_word_length': 3.704950495049505, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7541458', 'n_tokens_mistral': 790, 'n_tokens_neox': 755, 'n_words': 169}