<commit_before># encoding: utf-8

class AnswersController < ApplicationController
  before_filter :require_admin
  before_filter :get_question

  def new
    @answer = Answer.new
  end

  def edit
    @answer = Answer.find(params[:id])
  end

  def update
    @answer = Answer.find(params[:id])
    if @answer.update_attributes(params[:answer])
      flash[:success] = "Antwort aktualisiert"
      redirect_to @question
    else
      render 'edit'
    end
  end


  def create
    @answer = Answer.new(params[:answer])
    @answer.question = @question

    if @answer.save
      flash[:success] = "Antwort gespeichert"
      redirect_to @question
    else
      render 'new'
    end
  end

  def destroy
    @answer = Answer.find(params[:id])
    if @answer.destroy
      flash[:success] = "Antwort gelöscht"
    else
      flash[:error] = "Antwort konnte nicht gelöscht werden. Vermutlich steht in den Logs mehr."
    end
    redirect_to @question
  end

  private

  def get_question
    @question = Question.find(params[:question_id])
    unless @question
      flash[:warning] = "Frage mit dieser ID nicht gefunden."
      redirec_to questions_path
    end
  end
end
<commit_msg>auto-increment answer-ident (fixes #51)<commit_after># encoding: utf-8

class AnswersController < ApplicationController
  before_filter :require_admin
  before_filter :get_question

  def new
    @answer = Answer.new
    @answer.ident ||= gen_answer_ident(@question)
  end

  def edit
    @answer = Answer.find(params[:id])
  end

  def update
    @answer = Answer.find(params[:id])
    if @answer.update_attributes(params[:answer])
      flash[:success] = "Antwort aktualisiert"
      redirect_to @question
    else
      render 'edit'
    end
  end


  def create
    @answer = Answer.new(params[:answer])
    @answer.question = @question

    if @answer.save
      flash[:success] = "Antwort gespeichert"
      redirect_to @question
    else
      render 'new'
    end
  end

  def destroy
    @answer = Answer.find(params[:id])
    if @answer.destroy
      flash[:success] = "Antwort gelöscht"
    else
      flash[:error] = "Antwort konnte nicht gelöscht werden. Vermutlich steht in den Logs mehr."
    end
    redirect_to @question
  end

  private

  def get_question
    @question = Question.find(params[:question_id])
    unless @question
      flash[:warning] = "Frage mit dieser ID nicht gefunden."
      redirec_to questions_path
    end
  end

  def gen_answer_ident(question)
    idents = question.answers.map { |a| a.ident.to_s }
    id = question.answers.size + 1
    5.times do
      break unless idents.include?(id.to_s)
      id += 1
    end
    id.to_s
  end
end

{'fraction_non_alphanumeric': 0.09486314210723659, 'fraction_numerical': 0.0026246719160104987, 'mean_word_length': 2.8666666666666667, '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': '2748303', 'n_tokens_mistral': 864, 'n_tokens_neox': 850, 'n_words': 222}