<commit_before>class ApplicantsController < ApplicationController

  def new
  end

  def create
    @applicant = Applicant.new

    @applicant.identity = add_a_new_person(@applicant)
    @applicant.identity.first_name = params[:first_name]
    @applicant.identity.last_name = params[:last_name]
    @applicant.user = current_user

    success = false

    Applicant.transaction do
      params[:household_member_count].to_i.times do
        @applicant.household_members << add_new_household_member(@applicant)
      end
      params[:residence_count].to_i.times do
        @applicant.residences << add_new_residence(@applicant)
      end
      params[:income_count].to_i.times do
        add_new_income(@applicant)
      end
      params[:employment_count].to_i.times do
        @applicant.identity.employments << add_new_employment(@applicant)
      end
      success = @applicant.save
    end

    if success
      session[:current_applicant_id] = @applicant.id
      redirect_to edit_person_path(@applicant.identity)
    else
      render :new
    end
  end

  def show
    @applicant = Applicant.find(params[:id])
    session[:current_applicant_id] = @applicant.id
  end

  def update
    @applicant = current_applicant
    @applicant.update_attributes(params[:applicant])

    respond_to do |format|
      format.html { redirect_to apply_path }
    end
  end

  def destroy
    applicant = Applicant.find(params[:id])
    applicant.destroy if applicant
    redirect_to root_path
  end

  private

  def add_new_employment applicant
    Employment.create do |e|
      e.address = Address.create
    end
  end
<commit_msg>Assign current applicant in applicant#show<commit_after>class ApplicantsController < ApplicationController

  def new
  end

  def create
    @applicant = Applicant.new

    @applicant.identity = add_a_new_person(@applicant)
    @applicant.identity.first_name = params[:first_name]
    @applicant.identity.last_name = params[:last_name]
    @applicant.user = current_user

    success = false

    Applicant.transaction do
      params[:household_member_count].to_i.times do
        @applicant.household_members << add_new_household_member(@applicant)
      end
      params[:residence_count].to_i.times do
        @applicant.residences << add_new_residence(@applicant)
      end
      params[:income_count].to_i.times do
        add_new_income(@applicant)
      end
      params[:employment_count].to_i.times do
        @applicant.identity.employments << add_new_employment(@applicant)
      end
      success = @applicant.save
    end

    if success
      session[:current_applicant_id] = @applicant.id
      redirect_to edit_person_path(@applicant.identity)
    else
      render :new
    end
  end

  def show
    @applicant = Applicant.find(params[:id])
    session[:current_applicant_id] = @applicant.id
    assign_current_applicant
  end

  def update
    @applicant = current_applicant
    @applicant.update_attributes(params[:applicant])

    respond_to do |format|
      format.html { redirect_to apply_path }
    end
  end

  def destroy
    applicant = Applicant.find(params[:id])
    applicant.destroy if applicant
    redirect_to root_path
  end

  private

  def add_new_employment applicant
    Employment.create do |e|
      e.address = Address.create
    end
  end

{'fraction_non_alphanumeric': 0.08066465256797584, 'fraction_numerical': 0.0, 'mean_word_length': 3.201776649746193, 'pattern_counts': {'":': 0, '<': 17, '<?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': '2352621', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1002, 'n_words': 197}