<commit_before>class EquipmentObjectsController < ApplicationController
  before_filter :require_admin, :except => :index
  before_filter :require_checkout_person, :only => :index
  before_filter :set_current_equipment_object, :only => [:show, :edit, :update, :destroy]
  before_filter :set_equipment_model_if_possible, :only => [:index, :new]

  include ActivationHelper

  # ---------- before filter methods ---------- #

  def set_current_equipment_object
    @equipment_object = EquipmentObject.find(params[:id])
  end

  def set_equipment_model_if_possible
    @equipment_model = EquipmentModel.find(params[:equipment_model_id]) if params[:equipment_model_id]
  end

  # ---------- end before filter methods ---------- #


  def index
    if params[:equipment_model_id]
      @equipment_objects = @equipment_model.equipment_objects
    elsif params[:show_deleted]
      @equipment_objects = EquipmentObject.all
    else
      @equipment_objects = EquipmentObject.active
    end
  end

  def show
  end

  def new
    @equipment_object = EquipmentObject.new(equipment_model: @equipment_model)
  end

  def create
    @equipment_object = EquipmentObject.new(params[:equipment_object])
    if @equipment_object.serial == "Enter serial # (optional)"
      @equipment_object.serial = nil
    end
    if @equipment_object.save
      flash[:notice] = "Successfully created equipment object. #{@equipment_object.serial}"
      redirect_to @equipment_object.equipment_model
    else
      render :action => 'new'<commit_msg>Refactored index method to account for belonging to an equipment model and fixed variable name problem<commit_after>class EquipmentObjectsController < ApplicationController
  before_filter :require_admin, :except => :index
  before_filter :require_checkout_person, :only => :index
  before_filter :set_current_equipment_object, :only => [:show, :edit, :update, :destroy]
  before_filter :set_equipment_model_if_possible, :only => [:index, :new]

  include ActivationHelper

  # ---------- before filter methods ---------- #

  def set_current_equipment_object
    @equipment_object = EquipmentObject.find(params[:id])
  end

  def set_equipment_model_if_possible
    @equipment_model = EquipmentModel.find(params[:equipment_model_id]) if params[:equipment_model_id]
  end

  # ---------- end before filter methods ---------- #


  def index
    if params[:show_deleted]
      @equipment_objects = ( @equipment_object ? @equipment_object.equipment_models : EquipmentObject.all )
    else
      @equipment_objects = ( @equipment_object ? @equipment_object.equipment_models.active : EquipmentObject.active )
    end
  end

  def show
  end

  def new
    @equipment_object = EquipmentObject.new(equipment_model: @equipment_model)
  end

  def create
    @equipment_object = EquipmentObject.new(params[:equipment_object])
    if @equipment_object.serial == "Enter serial # (optional)"
      @equipment_object.serial = nil
    end
    if @equipment_object.save
      flash[:notice] = "Successfully created equipment object. #{@equipment_object.serial}"
      redirect_to @equipment_object.equipment_model
    else
      render :action => 'new'
{'fraction_non_alphanumeric': 0.10829639012032932, 'fraction_numerical': 0.0, 'mean_word_length': 4.022257551669316, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '4731851', 'n_tokens_mistral': 981, 'n_tokens_neox': 908, 'n_words': 202}