<commit_before>class UsersController < ApplicationController

  def index
    @users = User.all
  end

  def new
    @user = User.new
    @countries_select_array = Country.countries_as_select_list
    @languages_select_array = Language.languages_as_select_list
  end

  def create
    user = User.find_by(username: user_params[:username])
    if !user
      @user = User.new(user_params)
      @user.level = Level.find_by(language_id: user_params[:study_language_id],
        name: "beginner")
      if @user.save
        session[:user_id] = @user.id
        flash[:notice] = ["Successfully registered."]
        redirect_to root_path
      else
        flash[:alert] = ["A user with that name or email already exists"]
        redirect_to new_user_path
      end
    else
      flash[:alert] = ["A user with that username already exists."]
      redirect_to new_user_path
    end
  end

  def edit
    find_user
  end

  def update
    find_user
    @user.assign_attributes(user_params)
    if @user.save
      redirect_to @user
    else
      render :edit
    end
  end

  def show
    find_user
  end

  def destroy
    find_user
    @user.destroy if @user
    redirect_to root_path
  end

  private

  def user_params
    params.require(:user).permit(:username, :email, :password, :country_id, :native_language_id,
      :study_language_id, :avatar_url, :points, :level_id, :last_seen_at)
  end

  def find_user
    @user = User.find_by(id: params[:id])
  end
end
<commit_msg>Remove unused actions and use helper for finding a beginner level language<commit_after>class UsersController < ApplicationController

  def new
    @user = User.new
    @countries_select_array = Country.countries_as_select_list
    @languages_select_array = Language.languages_as_select_list
  end

  def create
    user = User.find_by(username: user_params[:username])
    if !user
      @user = User.new(user_params)
      @user.level = Level.find_beginner_language(user_params[:study_language_id])
      if @user.save
        session[:user_id] = @user.id
        flash[:notice] = ["Successfully registered."]
        redirect_to root_path
      else
        flash[:alert] = ["A user with that username or email already exists"]
        redirect_to new_user_path
      end
    else
      flash[:alert] = ["A user with that username already exists."]
      redirect_to new_user_path
    end
  end

  private

  def user_params
    params.require(:user).permit(:username, :email, :password, :country_id, :native_language_id,
      :study_language_id, :avatar_url, :points, :level_id, :last_seen_at)
  end

end

{'fraction_non_alphanumeric': 0.08490930142802007, 'fraction_numerical': 0.0, 'mean_word_length': 3.088328075709779, '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': '7131298', 'n_tokens_mistral': 825, 'n_tokens_neox': 809, 'n_words': 203}