簡體   English   中英

頁面未在提交時重定向(Rails商店結帳)

[英]Page Not Redirecting on Submit (Shoppe Checkout with Rails)

我正在遵循本文檔,嘗試使用Shoppe gem在我的應用程序上創建購物車/結帳。 我擁有文檔中的所有代碼,但是當我單擊orders#checkout頁面上的“ Checkout”按鈕時,似乎什么都沒有發生。 這是orders_controller

class OrdersController < ApplicationController
    def destroy
      current_order.destroy
      session[:order_id] = nil
      redirect_to root_path, :notice => "Basket emptied successfully."
    end

    def checkout
      @order = Shoppe::Order.find(current_order.id)
      if request.patch?  << USING BYEBUG, THIS CONDITION IS FALSE
        if @order.proceed_to_confirm(params[:order].permit(:first_name, :last_name, :billing_address1, :billing_address2, :billing_address3, :billing_address4, :billing_country_id, :billing_postcode, :email_address, :phone_number))
          redirect_to checkout_payment_path
        end
      end
    end

    def payment
      if request.post?
        redirect_to checkout_confirmation_path
      end
    end

    def confirmation
      if request.post?
        current_order.confirm!
        session[:order_id] = nil
        redirect_to root_path, :notice => "Order has been placed successfully!"
      end
    end
end

這是我的orders/checkout.html.erb的內容:

<div class="container">
    <h2 class="text-center">Checkout</h2>

    <%= render 'items', :order => @order %>

    <h2 style="margin-top: 50px">Billing Information</h2>

    <div class="blue-box text-center">
        <%= form_for @order, :url => checkout_path do |f| %>
            <div class="form-group col-xs-6 text-left">
            <%= f.label :first_name, 'First Name' %>
            <% if current_user && current_user.first_name %>
                <%= f.text_field :first_name, required: true, class: 'form-control', value: current_user.first_name  %>
            <% else %>
                <%= f.text_field :first_name, class: "form-control" %>
            <% end %>
            </div>
            <div class="form-group col-xs-6 text-left">
                <%= f.label :last_name, 'Last Name' %> 
                <% if current_user && current_user.last_name %>
                    <%= f.text_field :last_name, required: true, class: 'form-control', value: current_user.last_name  %>
                <% else %>
                    <%= f.text_field :last_name, class: "form-control" %>
                <% end %>
            </div>

            <div class="form-group col-xs-12 text-left">
                <%= f.label :billing_address1, 'Address' %>
                <%= f.text_field :billing_address1, class: "form-control", placeholder: "Line 1" %>
                <%= f.text_field :billing_address2, class: "form-control", placeholder: "Line 2" %>
                <%= f.text_field :billing_address3, class: "form-control", placeholder: "Line 3" %>
                <%= f.text_field :billing_address4, class: "form-control", placeholder: "Line 4" %>
            </div>

            <div class="form-group col-xs-6 text-left">
                <%= f.label :billing_postcode, 'Zip/Post Code' %>
                <%= f.text_field :billing_postcode, class: "form-control" %>
            </div>
            <div class="form-group col-xs-6 text-left">
                <%= f.label "Country" %>
                <%= f.collection_select :billing_country_id, Shoppe::Country.ordered, :id, :name, :include_blank => true %>
            </div>

            <div class="form-group col-xs-6 text-left">
                <%= f.label :email_address %>
                <% if current_user && current_user.email %>
                    <%= f.text_field :email_address, required: true, class: 'form-control', value: current_user.email  %>
                <% else %>
                    <%= f.text_field :email_address, class: "form-control" %>
                <% end %>
            </div>
            <div class="form-group col-xs-6 text-left">
                <%= f.label :phone_number %>
                <% if current_user && current_user.phone %>
                    <%= f.text_field :phone, required: true, class: 'form-control', value: current_user.phone  %>
                <% else %>
                    <%= f.text_field :phone_number, class: "form-control" %>
                <% end %>
            </div>
                <%= f.submit 'Continue', class: "btn cta" %>
        <% end %>
    </div> <!-- blue box -->

</div> <!-- container -->

<script type="text/javascript">
  $(document).ready(function(){
    $(".footer").removeClass("top-shadow-inset");
  });
</script>

正在呈現的“ items”部分在下面,但是它也顯示在沒有此問題的其他頁面上,因此可能不是問題:

<table width='100%' border='1' class="cart-table">
  <% if order.order_items.count == 0 %>

    <thead>
      <tr>
        <td colspan='5' class="text-center"><h3>You currently have no items in your cart!<br>Check out our <%= link_to "store", products_path %> for some awesome stuff!</h3></td>
      </tr>
    </thead>

  <% else %>

    <thead>
      <tr>
        <td>Quantity</td>
        <td>Product</td>
        <td>Sub-Total</td>
        <td>Tax</td>
        <td>Total</td>
      </tr>
    </thead>
    <tbody>
      <% order.order_items.each do |item| %>
      <tr>
        <td><%= item.quantity %></td>
        <td><%= item.ordered_item.full_name %></td>
        <td><%= number_to_currency item.sub_total %></td>
        <td><%= number_to_currency item.tax_amount %></td>
        <td><%= number_to_currency item.total %></td>
      </tr>
      <% end %>

      <% if order.delivery_service %>
      <tr>
        <td></td>
        <td><%= order.delivery_service.name %></td>
        <td><%= number_to_currency order.delivery_price %></td>
        <td><%= number_to_currency order.delivery_tax_amount %></td>
        <td><%= number_to_currency order.delivery_price + order.delivery_tax_amount %></td>
      </tr>
      <% end %>
    </tbody>

    <tfoot>
      <tr>
        <td colspan='4' class="text-right">Sub-Total</td>
        <td><%= number_to_currency order.total_before_tax %></td>
      </tr>
      <tr>
        <td colspan='4' class="text-right">Tax</td>
        <td><%= number_to_currency order.tax %></td>
      </tr>
      <tr>
        <td colspan='4' class="text-right">Total</td>
        <td><%= number_to_currency order.total %></td>
      </tr>
    </tfoot>

  <% end %>
</table>

誰能看到導致此問題的原因嗎? 沒有相關的控制台錯誤,當我單擊checkout時,我的服務器非常詳細:

Started PATCH "/checkout" for ::1 at 2017-03-25 11:12:40 -0700
Processing by OrdersController#checkout as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"BFvhlQYmGP2LBLKcrvCsJ0oTdg+Qh7KcGWRPh3YhmBfEIwW+a4VrrxmsaIbY1Yn2Kl4Yt4vbNt+dM4NKY7LZ/w==", "order"=>{"first_name"=>"Liz", "last_name"=>"Bayardelle", "billing_address1"=>"", "billing_address2"=>"", "billing_address3"=>"", "billing_address4"=>"", "billing_postcode"=>"", "billing_country_id"=>"", "email_address"=>"lizbayardelle@gmail.com", "phone"=>"949-939-0622"}, "commit"=>"Continue"}
  Shoppe::Order Load (0.1ms)  SELECT  "shoppe_orders".* FROM "shoppe_orders" WHERE "shoppe_orders"."id" = ? LIMIT 1  [["id", 2]]
  Shoppe::OrderItem Load (0.2ms)  SELECT "shoppe_order_items".* FROM "shoppe_order_items" WHERE "shoppe_order_items"."order_id" IN (2)
  Shoppe::Product Load (0.2ms)  SELECT "shoppe_products".* FROM "shoppe_products" WHERE "shoppe_products"."id" IN (1, 2)
  CACHE (0.0ms)  SELECT  "shoppe_orders".* FROM "shoppe_orders" WHERE "shoppe_orders"."id" = ? LIMIT 1  [["id", 2]]
Unpermitted parameter: phone
   (0.1ms)  begin transaction
  Shoppe::OrderItem Load (0.1ms)  SELECT "shoppe_order_items".* FROM "shoppe_order_items" WHERE "shoppe_order_items"."order_id" = ?  [["order_id", 2]]

  ...

   (0.1ms)  rollback transaction
   (0.1ms)  SELECT COUNT(*) FROM "shoppe_order_items" WHERE "shoppe_order_items"."order_id" = ?  [["order_id", 2]]
  Shoppe::Product::Translation Load (0.1ms)  SELECT "shoppe_product_translations".* FROM "shoppe_product_translations" WHERE "shoppe_product_translations"."shoppe_product_id" = ?  [["shoppe_product_id", 1]]
  Shoppe::Product Load (0.1ms)  SELECT "shoppe_products".* FROM "shoppe_products" WHERE "shoppe_products"."parent_id" = ?  [["parent_id", 1]]
  ...

  Rendered orders/_items.html.erb (64.8ms)
  User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
  Shoppe::Country Load (0.8ms)  SELECT "shoppe_countries".* FROM "shoppe_countries"  ORDER BY "shoppe_countries"."name" ASC
  Rendered orders/checkout.html.erb within layouts/application (77.2ms)
  Rendered layouts/_cart_text.html.erb (1.0ms)
Completed 200 OK in 200ms (Views: 177.9ms | ActiveRecord: 4.1ms)

不允許的參數:電話

您需要在控制器中允許該屬性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM