<commit_before># TODO: by using STI, should I break apart BitsController into sublass controllers?
class BitsController < ApplicationController

  #TODO: prevent save of bit position below 0/0 until ZUI is implemented

  protect_from_forgery


  def show
    @bit = Bit.find(params[:id])

    respond_to do |format|
      format.html { render :layout => false }
    end
  end



  def new
    @bit = Bit.new

    # set position, if available
    if params[:position_x] && params[:position_y]
      @bit.position_x = params[:position_x]
      @bit.position_y = params[:position_y]
    end    

    respond_to do |format|
      format.html { render :layout => false }
    end
  end


  def create


    if params[:bit] && params[:bit][:content]
      @bit = Text.new
      @bit.content = params[:bit][:content]   
      @bit.position_x = params[:bit][:position_x]
      @bit.position_y = params[:bit][:position_y]
    
    else
      @bit = Image.new

       # 2 methods images can get added, during testing:
      # via form, in which everything is contained in the [:bit][:image] hash

      # prepare in case it comes outs
      if params[:bit] && params[:bit][:content]

      # TODO: why can't I set this?
      # @bit.content = params[:files].first.original_filename
      # @bit.position_x = params[:position_x]
      # @bit.position_y = params[:position_y]
      @bit.position_x = params[:bit][:position_x]
      @bit.position_y = params[:bit][:position_y]
      @bit.image = params[:bit][:image]

      @bit.cascade_position # calc offsets if multiple images are dragged at once
    end

    @p = @bit.parallels.build
    @p.bind_to_closest_cluster

    respond_to do |format|
      if @bit.save
<commit_msg>fixed bug in bit:new controller affecting update action<commit_after># TODO: by using STI, should I break apart BitsController into sublass controllers?
class BitsController < ApplicationController

  #TODO: prevent save of bit position below 0/0 until ZUI is implemented

  protect_from_forgery


  def show
    @bit = Bit.find(params[:id])

    respond_to do |format|
      format.html { render :layout => false }
    end
  end



  def new
    @bit = Bit.new

    # set position, if available
    if params[:position_x] && params[:position_y]
      @bit.position_x = params[:position_x]
      @bit.position_y = params[:position_y]
    end    

    respond_to do |format|
      format.html { render :layout => false }
    end
  end


  def create


    if params[:bit] && params[:bit][:content]
      @bit = Text.new
      @bit.content = params[:bit][:content]   
      @bit.position_x = params[:bit][:position_x]
      @bit.position_y = params[:bit][:position_y]
    
    else
      @bit = Image.new

      @bit.position_x = params[:bit][:position_x]
      @bit.position_y = params[:bit][:position_y]
      @bit.image = params[:bit][:image]

      @bit.cascade_position # calc offsets if multiple images are dragged at once
    end

    @p = @bit.parallels.build
    @p.bind_to_closest_cluster

    respond_to do |format|
      if @bit.save

{'fraction_non_alphanumeric': 0.11147433801896045, 'fraction_numerical': 0.0016345210853220007, 'mean_word_length': 2.849056603773585, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2211940', 'n_tokens_mistral': 997, 'n_tokens_neox': 950, 'n_words': 263}