<commit_before>#encoding:utf-8
class UserAddressesController < ApplicationController
  before_action :validate_user!
  before_action only: [:show, :edit, :update, :destroy] do
    validate_permission!(set_user_address.user)
  end
  before_action :set_user_address, only: [:edit, :update, :destroy]

  def new
    @user_address = UserAddress.new
  end

  def create
    @user_address = UserAddress.new(user_address_params)
    @user_address.user = current_user

    if@user_address.save
      if params[:default] == '1'
        if user_address = UserAddress.where(default: 1)
          user_address.first.update(default: 0)
          @user_address.update(default: 1)
        end
      end
      if params[:groupbuy_id].present?
        return redirect_to user_addresses_path(groupbuy_id: params[:groupbuy_id])
      end
      redirect_to user_addresses_path, notice: '地址添加成功'
    else
      render :new
    end
  end

  def show
    @user_address = UserAddress.find(params[:id])
  end

  def edit()
  end

  def update
    if params[:from] == 'ajax'
      if user_address = UserAddress.where(default: 1)
        user_address.first.update(default: 0)
      end
      UserAddress.find(params[:id]).update(default: 1)
      return render text: 'success'
    end

    if @user_address.update(user_address_params)
      if params[:default] == '1'
        if user_address = UserAddress.where(default: 1)
          user_address.first.update(default: 0)
          @user_address.update(default: 1)
        end
      end
<commit_msg>fix bug<commit_after>#encoding:utf-8
class UserAddressesController < ApplicationController
  before_action :validate_user!
  before_action only: [:show, :edit, :update, :destroy] do
    validate_permission!(set_user_address.user)
  end
  before_action :set_user_address, only: [:edit, :update, :destroy]

  def new
    @user_address = UserAddress.new
  end

  def create
    @user_address = UserAddress.new(user_address_params)
    @user_address.user = current_user

    if@user_address.save
      if params[:default] == '1'
        user_address = UserAddress.where(default: 1)
        if user_address.present?
          user_address.first.update(default: 0)
          @user_address.update(default: 1)
        end
      end
      if params[:groupbuy_id].present?
        return redirect_to user_addresses_path(groupbuy_id: params[:groupbuy_id])
      end
      redirect_to user_addresses_path, notice: '地址添加成功'
    else
      render :new
    end
  end

  def show
    @user_address = UserAddress.find(params[:id])
  end

  def edit()
  end

  def update
    if params[:from] == 'ajax'
      user_address = UserAddress.where(default: 1)
      if user_address.present?
        user_address.first.update(default: 0)
      end
      UserAddress.find(params[:id]).update(default: 1)
      return render text: 'success'
    end

    if @user_address.update(user_address_params)
      if params[:default] == '1'
        if user_address = UserAddress.where(default: 1)
          user_address.first.update(default: 0)
          @user_address.update(default: 1)
        end
      end

{'fraction_non_alphanumeric': 0.09819121447028424, 'fraction_numerical': 0.007751937984496124, 'mean_word_length': 3.0325520833333335, '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': '1680539', 'n_tokens_mistral': 1010, 'n_tokens_neox': 977, 'n_words': 211}