ECサイトの注文機能を作っていたのですが、注文機能自体は完成し、完了画面に遷移した時にパスはあっていて、ターミナルにエラーも出ていないのになぜかviewだけが表示されません。このようなことは初めてなので対処法がわからなくなってしまいました。
orders_controller
class Public::OrdersController < ApplicationController before_action :authenticate_customer! def index end def show end def new @order = Order.new @customer = current_customer @addresses = current_customer.addresses end def create @order = Order.new(order_params) @order.customer_id = current_customer.id if @order.save! @cart_items = current_customer.cart_items @cart_items.each do |cart_item| order_detail = OrderDetail.new(order_id: @order.id) order_detail.price = cart_item.item.price order_detail.amount = cart_item.amount order_detail.item_id = cart_item.item_id order_detail.save! end @cart_items.destroy_all redirect_to orders_complete_path else render "new" end end def confirm @cart_items = current_customer.cart_items @order = Order.new(order_params) @order.customer_id = current_customer.id @order.payment_method = params[:order][:payment_method] @total_payment = current_customer.cart_items.cart_items_total_price(@cart_items) @order.shipping_cost = 800 if params[:order][:address_option] == "0" @order.postal_code = current_customer.postal_code @order.address = current_customer.address @order.name = current_customer.full_name_a render 'confirm' elsif params[:order][:address_option] == "1" @address = Address.find(params[:order][:address_id]) @order.postal_code = @address.postal_code @order.address = @address.address @order.name = @address.name render 'confirm' elsif params[:order][:address_option] == "2" @address = current_customer.addresses.new @address.address = params[:order][:address] @address.name = params[:order][:name] @address.postal_code = params[:order][:postal_code] @address.customer_id = current_customer.id if @address.save @order.postal_code = @address.postal_code @order.name = @address.name @order.address = @address.address else render 'new' end end end def complete end private def order_params params.require(:order).permit(:postal_code,:address, :name, :shipping_cost, :address, :total_payment, :payment_method, :status) end def address_params params.require(:address).permit(:customer_id, :name, :postal_code, :address) end end
<div class="container"> <h2 class="border-bottom">注文情報確認</h2> <div class="row"> <div class="col-xs-8"> <table class="table table-striped table-bordered table-hover table-sm"> <thead> <tr> <th>商品名</th> <th>単価(税込)</th> <th>数量</th> <th>小計</th> </tr> </thead> <tbody> <% @cart_items.each do |cart_item| %> <tr> <td> <%= image_tag cart_item.item.get_image, size: '50x50' %> <%= cart_item.item.name %> </td> <td><%= (cart_item.item.price * 1.1).floor.to_s(:delimited) %></td> <td><%= cart_item.amount %></td> <td><%= (cart_item.item.price * cart_item.amount * 1.1).floor.to_s(:delimited) %></td> </tr> <% end %> </tbody> </table> </div> <%= form_with model: @order, url: orders_path, local: true do |f| %> <div class="col-xs-3"> <table class="table table-striped table-bordered table-hover table-sm"> <tbody> <tr> <td>送料</td> <td> <%= @order.shipping_cost.to_s(:delimited) %> <%= f.hidden_field :address, :value => @order.address %> </td> </tr> <tr> <td>商品合計</td> <td> <%= @total_payment.to_s(:delimited) %> </td> </tr> <tr> <td>請求金額</td> <td> <%= (@total_payment + 800).to_s(:delimited) %> <%= f.hidden_field :total_payment, :value => (@total_payment + 800) %> </td> </tr> </tbody> </table> </div> </div> <div class="form-group"> <h3>支払方法:</h3> <h4><%= @order.payment_method_i18n %></h4> <%= f.hidden_field :payment_method, :value => @order.payment_method %> </div> <div class="form-group"> <h3>お届け先:</h3> 〒<%= @order.postal_code.to_s %> <%= f.hidden_field :postal_code, :value => @order.postal_code %> <%= @order.address %> <%= f.hidden_field :address, :value => @order.address %> <%= @order.name %> <%= f.hidden_field :name, :value => @order.name %> </div> <div class="text-left"> <%= link_to "情報入力へ戻る", new_order_path, class: "btn btn-primary" %> </div> <div class="text-center"> <%= f.submit "購入を確定する", class: "btn btn-success btn-lg text-center" %> </div> <% end %> </div>
そして次のが問題の読み込まれていないviewです。
complete.html.erb
<div class="container"> <div class="row"> <h1 class="text-center">ご注文ありがとうございました!!</h1> <div class="text-center"> <%= link_to "トップページへ戻る", root_path, class: "btn btn-primary" %> </div> </div> </div>
コードの書き方が見にくいかもしれないですが、アドバイスお願いいたします
0 コメント