前提・実現したいこと
railsで簡単なECサイトを作る練習をしており、注文ステータスの非同期通信を実装しようとしたところエラーが出てしまいました。
##発生している問題・エラーメッセージ
ActionView::MissingTemplate in Admin::Orders#show
Showing /home/ec2-user/environment/nagano_cake/app/views/admin/orders/show.html.erb where line #36 raised:
Missing partial admin/orders/_order_status, application/_order_status with {:locale=>[:ja], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :jbuilder]}. Searched in:
- "/home/ec2-user/environment/nagano_cake/app/views"
- "/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/kaminari-core-1.2.1/app/views"
- "/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/devise-4.8.0/app/views
##関連のありそうなソースコード
_orders/show.html
Ruby
1 <div class="container-fluid mx-5"> 2 <div class="mx-9 mt-5"><h3>注文履歴詳細</h3></div> 3 4 <table class="table table-borderless"> 5 <tbody> 6 <tr> 7 <th>購入者</th> 8 <td><%= link_to admin_customer_path(@order.customer) do %><!--要確認--> 9 <%= @order.customer.last_name %> <%= @order.customer.first_name %> 10 <% end %> 11 </td> 12 </tr> 13 14 <tr> 15 <th>注文日</th> 16 <td><%= l @order.created_at, format: :short %></td> 17 </tr> 18 19 <tr> 20 <th>配送先</th> 21 <td> 22 <%= @order.shipping_postal_code %> 23 <%= @order.delivery_address %> 24 <%= @order.receiver_name %> 25 </td> 26 </tr> 27 28 <tr> 29 <th>支払い方法</th> 30 <td><%= @order.payment_method %></td> 31 </tr> 32 33 <tr> 34 <th>注文ステータス</th> 35 <td id="order_status_<%= @order.id %>"> 36 <%= render partial: 'orders/order_status', locals: { order: @order} %> 37 </td> 38 <%#= form_with model: [:admin, @order], method: :patch, local: true do |f| %> 39 <%#= f.select :order_status, Order.order_statuses.keys.map {|k| [I18n.t("enums.order.order_status.#{k}"), k]} %> 40 <%#= f.submit "更新" %> 41 <%# end %> 42 </td> 43 </tr> 44 </tbody> 45 </table> 46 47 48 <div class="row align-items-end"> 49 <div class="col-md-7"> 50 <table class="table table-borderless"> 51 <thead class="table-head" style="background-color:#FFE4E1;"> 52 <tr> 53 <th scope="col">商品名</th> 54 <th scope="col">単価(税込)</th> 55 <th scope="col">数量</th> 56 <th scope="col">小計</th> 57 <th scope="col">製作ステータス</th> 58 </tr> 59 </thead> 60 <tbody> 61 <% @order_items.each do |order_item| %> 62 <tr> 63 <td><%= order_item.item.item_name %></td> 64 <td><%= order_item.tax_price %></td> 65 <td><%= order_item.number_of_piaces %></td> 66 <td><%= (order_item.tax_price.to_i * order_item.number_of_piaces.to_i).to_s(:delimited) %></td> 67 <td> 68 <%= form_with model: order_item, url: admin_order_order_item_path(@order,order_item), method: :patch, local: true do |f| %> 69 <%= f.select :production_status, OrderItem.production_statuses.keys.map {|k| [I18n.t("enums.order_item.production_status.#{k}"), k]} %> 70 <%= f.submit "更新" %> 71 <% end %> 72 </td> 73 </tr> 74 <% end %> 75 </tbody> 76 </table> 77 </div> 78 79 <th></th> 80 81 <div class="col-md-4"> 82 <table class="table table-borderless"> 83 <tbody> 84 <tr> 85 <th>商品合計</th><td><%= (@order.total_price.to_i - @order.shipping_fee.to_i).to_s(:delimited) %>円</td> 86 </tr> 87 88 <tr> 89 <th>送料</th><td><%= @order.shipping_fee.to_s(:delimited) %>円</td> 90 </tr> 91 92 <tr> 93 <th>請求金額合計</th><td><%= (@order.total_price.to_i).to_s(:delimited) %>円</td> 94 </tr> 95 </tbody> 96 </table> 97 </div> 98 </div> 99</div> 100
orders/_order_status.html
ruby
1<%= form_with model: [:admin, @order], method: :patch, remote: true do |f| %> 2<%= f.select :order_status, Order.order_statuses.keys.map {|k| [I18n.t("enums.order.order_status.#{k}"), k]} %> 3<%= f.submit "更新" %> 4<% end %> 5
orders/update.js
ruby
1$('#order_status_<%= @order.id %>').html("<%= j(render partial: 'orders/order_status', locals: {order: @order}) %>");
ファイルの階層等見直しましたが、原因がわかりませんでした。
お力添え願います。不足した情報があればご指摘ください。
よろしくお願いいたします。
追記
ご指摘いただきましたので、追記いたします
_routes.rb
ruby
1Rails.application.routes.draw do 2 3 #管理者 4 devise_for :admin, skip: [:registrations, :passwords] ,controllers: { 5 sessions: 'admin/sessions', 6 } 7 8 namespace :admin do 9 get 'admin/new', to: 'admin/sessions#new' 10 11 #items 12 resources :items, only:[:new, :show, :index, :edit, :create, :update] 13 14 #genres 15 resources :genres, only:[:index, :edit, :create, :update] 16 17 #customers 18 resources :customers, only:[:index, :edit, :show, :update] 19 20 #orders 21 resources :orders, only:[:index, :show, :update] do 22 #oder_items 23 resources :order_items, only:[:index, :update] 24 end 25 26 end 27 28 29 #会員 30 devise_for :customers,skip: [:passwords,], controllers: { 31 registrations: 'customers/registrations', 32 sessions: 'customers/sessions', 33 } 34 35 36 scope module: :public do 37 38 #homes 39 root 'homes#top' 40 get 'homes/about' => 'homes#about' 41 42 #items 43 resources :items, only:[:show, :index] 44 45 #cart_items 46 resources :cart_items, only:[:index, :create, :update, :destroy] do 47 collection do 48 delete 'cart_items/destroy_all' => 'cart_items#destroy_all' 49 end 50 end 51 52 #orders 53 resources :orders, only:[:new, :show, :index, :create] do 54 collection do 55 post 'orders/confirm' => 'orders#confirm' 56 get 'orders/complete' => 'orders#complete' 57 end 58 end 59 60 61 62 #customers 63 resources :customers, only:[:show, :edit, :update] do 64 collection do 65 get 'customers/leave' => 'customers#leave' 66 patch 'customers/out' => 'customers#out' 67 end 68 69 70 end 71 72 73 74 #deliveries 75 resources :deliveries, only:[:index, :create, :edit, :update, :destroy] 76 77 78 end 79 80 81 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 82 end 83
orders_controller
ruby
1class Admin::OrdersController < ApplicationController 2 before_action :authenticate_admin! 3 4 def index 5 @count = Order.where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day).count 6 @orders = Order.all.page(params[:page]).per(10) 7 8 case params[:order] 9 when 'today' 10 @orders = Order.page(params[:page]).where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day).per(10) #ここまでできてる 11 when 'customer' 12 customer_id = Rails.application.routes.recognize_path(request.referer)[:id] 13 @customer = Customer.find(customer_id) 14 @orders = @customer.orders.page(params[:page]).per(10) 15 16 end 17 18 def show 19 @order = Order.find(params[:id]) 20 @order_items = @order.order_items.all 21 end 22 23 end 24 25 def update 26 order = Order.find(params[:id]) 27 order_items = order.order_items 28 29 # if order.update(order_params) 30 # redirect_to admin_order_path(order), notice:"注文ステータスを更新しました"#非同期通信導入検討 31 # else 32 # render :show, alert: "注文ステータスを更新できませんでした" 33 # end 34 end 35 36 37 private 38 def order_params 39 params.require(:order).permit(:order_status) 40 end 41 42end 43
回答2件
あなたの回答
tips
プレビュー