<commit_before>class OrdersController < ApplicationController

  def new
    @address  = Address.new
    @member   = Member.new
    @order    = Order.new
    @order.build_billing_address
    @order.build_user
    @order.member_type = MemberType.find(params[:member_id])
    @demographic_info = DemographicInfo.new
  end

  def create
    address_params = params[:order].delete "address"
    member_params  = params[:order].delete "member"

    @order    = Order.new(params[:order])
    @address  = Address.new(address_params)
    @member   = Member.new(member_params)

    @order.user.address   = @address
    @order.user.member    = @member
    @order.user.is_member = true
    @order.user.password  = <PASSWORD>
    @order.user.name      = "#{@member.first_name} #{@member.last_name}"

    @member.year = Year.last

    @order.member_type = @member.member_type = MemberType.find(params[:order][:member_type_id])

    if @order.process_transaction
      OrderMailer.delay.thank_you_membership(@order)
      respond_to do |format|
        format.js { render :text => "#{@order.id}", :status => 200 }
      end
    else
      respond_to do |format|
        format.js { render :new, :layout => false, :status => :unprocessable_entity }
      end
    end
  end

  # thank you
  def show
    @order = Order.find(params[:id])
    respond_to do |format|
      format.html
      format.pdf do
        html = render_to_string(partial: "invoice", layout: false)
        kit = PDFKit.new(html, "margin-bottom" => "0.5in", "margin-top" => "0.5in", page_size: 'Letter')
        css_path =  if Rails.env == "production"
                      "#{Rails.root}/public/assets/invoice.css"
                    else
                      "#{Rails.root}/app/assets/stylesheets/invoice.css"
                    end
        kit.stylesheets << css_path
        send_data kit.to_pdf, filename: "#{@order.code}.pdf", type: 'application/pdf'
      end
    end
  end

end
<commit_msg>Instantiate DI when txn fails<commit_after>class OrdersController < ApplicationController

  def new
    @address  = Address.new
    @member   = Member.new
    @order    = Order.new
    @order.build_billing_address
    @order.build_user
    @order.member_type = MemberType.find(params[:member_id])
    @demographic_info = DemographicInfo.new
  end

  def create
    address_params = params[:order].delete "address"
    member_params  = params[:order].delete "member"

    @order    = Order.new(params[:order])
    @address  = Address.new(address_params)
    @member   = Member.new(member_params)

    @order.user.address   = @address
    @order.user.member    = @member
    @order.user.is_member = true
    @order.user.password  = <PASSWORD>(5).upcase
    @order.user.name      = "#{@member.first_name} #{@member.last_name}"

    @member.year = Year.last

    @order.member_type = @member.member_type = MemberType.find(params[:order][:member_type_id])
    @demographic_info = DemographicInfo.new

    if @order.process_transaction
      OrderMailer.delay.thank_you_membership(@order)
      respond_to do |format|
        format.js { render :text => "#{@order.id}", :status => 200 }
      end
    else
      respond_to do |format|
        format.js { render :new, :layout => false, :status => :unprocessable_entity }
      end
    end
  end

  # thank you
  def show
    @order = Order.find(params[:id])
    respond_to do |format|
      format.html
      format.pdf do
        html = render_to_string(partial: "invoice", layout: false)
        kit = PDFKit.new(html, "margin-bottom" => "0.5in", "margin-top" => "0.5in", page_size: 'Letter')
        css_path =  if Rails.env == "production"
                      "#{Rails.root}/public/assets/invoice.css"
                    else
                      "#{Rails.root}/app/assets/stylesheets/invoice.css"
                    end
        kit.stylesheets << css_path
        send_data kit.to_pdf, filename: "#{@order.code}.pdf", type: 'application/pdf'
      end
    end
  end

end

{'fraction_non_alphanumeric': 0.1270718232044199, 'fraction_numerical': 0.0037669512807634357, 'mean_word_length': 2.55625, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '2746904', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1260, 'n_words': 246}