<commit_before>class ScribblesController < ApplicationController

  def create
    if scribble_params['id'] == ""
      @scribble = Scribble.new(scribble_params)
    else
      @scribble = Scribble.find(scribble_params['id'])
      @scribble.update_attributes(scribble_params)
    end
    @scribble.save

    respond_to do |format|
      format.json { render :json => @post }
    end
  end

  private

  def scribble_params
    params[:scribble].slice :content, :std_course_id, :scribing_answer_id, :id
  end 

end<commit_msg>Fix bug -- multiple scribbles was created per user unless user refreshes page after first scribble<commit_after>class ScribblesController < ApplicationController

  def create
    if scribble_params['id'] != ""
      @scribble = Scribble.find(scribble_params['id'])
    else
      @scribble = Scribble.where({
        std_course_id: scribble_params[:std_course_id],
        scribing_answer_id: scribble_params[:scribing_answer_id]
      }).first
    end
    if @scribble
      @scribble.update_attributes(scribble_params)
    else
      @scribble = Scribble.new(scribble_params)
    end
    @scribble.save

    respond_to do |format|
      format.json { render :json => @post }
    end
  end

  private

  def scribble_params
    params[:scribble].slice :content, :std_course_id, :scribing_answer_id, :id
  end 

end
{'fraction_non_alphanumeric': 0.09239940387481371, 'fraction_numerical': 0.0, 'mean_word_length': 3.447019867549669, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4611947', 'n_tokens_mistral': 442, 'n_tokens_neox': 422, 'n_words': 92}