<commit_before>class AlbumsController < ApplicationController
  protect_from_forgery expect: [:create]
  def new
    @album = Album.new
  end

  def create
    file = params[:files]
    binary   = file[0].tempfile.read
    filename = file[0].original_filename
    File.binwrite("public/zip/#{filename}", binary)
    redirect_to root_path
  end

  def show
  end

  def edit
  end

  def update
  end

  def destroy
  end
end<commit_msg>[refactering] albums#new のリファクタ<commit_after>class AlbumsController < ApplicationController
  protect_from_forgery expect: [:create]
  before_action :set_file, only: [:create]

  def new
    @album = Album.new
  end

  def create
    begin
      File.binwrite(@path, @file.tempfile.read)
    rescue
      redirect_to new_album_path, alert: 'File Uploadに失敗'
    else
      redirect_to root_path
    end
  end

  def show
  end

  def edit
  end

  def update
  end

  def destroy
  end

  private

  def set_file
    return unless params[:files]
    @file = params[:files][0]
    @path = Rails.root.join('public', 'zip', @file.original_filename)
  end
end
{'fraction_non_alphanumeric': 0.0834862385321101, 'fraction_numerical': 0.0027522935779816515, 'mean_word_length': 3.0861423220973783, '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': '4806004', 'n_tokens_mistral': 373, 'n_tokens_neox': 362, 'n_words': 95}