页面不在提交时重定向(使用Rails进行专柜检查)

时间:2017-03-25 18:17:45

标签: ruby-on-rails

我正在关注this documentation尝试使用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>

任何人都可以看到导致此问题的原因吗?没有相关的控制台错误,当我点击结帐时,我的服务器非常详细:

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)

1 个答案:

答案 0 :(得分:0)

  

未经许可的参数:手机

您需要在控制器中允许此属性