##環境
Rails 5.0.7.2
ruby2.5.1
capistrano3
nginx
AWS(ec2)
Docker/docker-compose(開発環境)
##概要
現在上述の環境でWEBアプリのデプロイを行いました。
開発環境では正常に動作するのですが、本番環境でのみ発生するエラーがございます。
以下、本番環境でのみ発生するエラー
・投稿削除ボタンを押しても,destroy.html.erbに遷移しない
・編集ボタンを押してもedit.html.erbに遷移しない
です。
##コード
routes
routes.rb
1Rails.application.routes.draw do 2 root 'top#index' 3 4 devise_for :users, controllers: { 5 registrations: 'users/registrations', 6 sessions: 'users/sessions' 7 } 8 9 resources :users, only: [:show] 10 resources :shops do 11 resources :comments, only: %i[create destroy] 12 resources :likes, only: %i[create destroy] 13 end 14end
controller
shops_controller.rb
1class ShopsController < ApplicationController 2 before_action :authenticate_user!, except: %i[index show] 3 before_action :validate_shop, only: %i[edit update destroy] 4 before_action :set_shop, only: %i[show edit update destroy] 5 6 def index 7 @search = Shop.ransack(params[:q]) 8 @shops = @search.result.page(params[:page]).per(9).order('updated_at DESC') 9 @random = Shop.order('RAND()').limit(5) 10 end 11 12 def show 13 @comment = Comment.new if user_signed_in? 14 @comments = @shop.comments.includes(:user) 15 @hash = Gmaps4rails.build_markers(@shop) do |shop, marker| 16 marker.lat shop.latitude 17 marker.lng shop.longitude 18 marker.infowindow render_to_string(partial: 'shops/infowindow', locals: { shop: shop }) 19 end 20 end 21 22 def edit; end 23 24 def update 25 if @shop.update_attributes(shop_params) 26 redirect_to @shop, notice: '投稿が編集されました。' 27 else 28 flash.now[:alert] = '編集に失敗しました。' 29 render :edit 30 end 31 end 32 33 def new 34 @shop = Shop.new 35 end 36 37 def create 38 @shop = Shop.new(shop_params) 39 if @shop.save 40 redirect_to shops_path, notice: '投稿に成功しました。' 41 else 42 flash.now[:alert] = '投稿に失敗しました。' 43 render :new 44 end 45 end 46 47 def destroy 48 @shop.destroy 49 end 50 51 private 52 53 def shop_params 54 params.require(:shop).permit(:name, :text, :image, :address, :latitude, :longitude, :area).merge(user_id: current_user.id) 55 end 56 57 def validate_shop 58 @shop = Shop.find_by(id: params[:id]) 59 redirect_to shops_path if @shop.user_id != current_user.id 60 end 61 62 def set_shop 63 @shop = Shop.find(params[:id]) 64 end 65end
view
show.html.erb
1<div class="col s12 m6 l6 content"> 2 <div class="card"> 3 <div class="card-image"> 4 <%= image_tag @shop.image %> 5 <div class="flow-text" id="likes_buttons_<%= @shop.id %>"> 6 <%= render partial: 'shared/like', locals: { shop: @shop, likes: @likes} %> 7 </div> 8 <span class="card-title"><%= @shop.name%></span> 9 </div> 10 <div class="card-content show-content"> 11 <p class="show-text"><%= @shop.text %></p> 12 <% if @shop.user == current_user %> 13 <div class="show-icons right"> 14 <%= link_to edit_shop_path do %> 15 <i class="material-icons underline #ffab00 amber-text text-accent-4">edit</i></a> 16 <% end %> 17 <%= link_to shop_path, data: { confirm: "本当に削除しますか?" }, method: :delete do %> 18 <i class="material-icons underline #ffab00 amber-text text-accent-4">delete</i></a> 19 <% end %> 20 </div> 21 <% end %> 22 <br> 23 <%= link_to user_path(@shop.user_id), class:"valign-wrapper" do %> 24 <%= image_tag @shop.user.image,class:"right hoverable image-icon"%> 25 <h6 class="underline"><%= @shop.user.username %></h6> 26 <% end %> 27 </div> 28 </div> 29</div>
エラーログでは204エラーが出ている状況です。
以上です。
追記 ログ
削除ボタン
I, [2020-03-29T06:35:46.863725 #29210] INFO -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] Started DELETE "/shops/35" for 14.3.50.42 at 2020-03-29 06:35:46 +0000 I, [2020-03-29T06:35:46.864435 #29210] INFO -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] Processing by ShopsController#destroy as HTML I, [2020-03-29T06:35:46.864486 #29210] INFO -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] Parameters: {"authenticity_token"=>"rNVjNAdF1me295xZGcP+2ofnAg54t/IS8mHPKxuZpFwg3DpvJekGws4gZNq+PYGZHTE6mXIwoFjtfZHoKSxqIA==", "id"=>"35"} D, [2020-03-29T06:35:46.871138 #29210] DEBUG -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] User Load (2.8ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1 D, [2020-03-29T06:35:46.874529 #29210] DEBUG -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] Shop Load (2.8ms) SELECT `shops`.* FROM `shops` WHERE `shops`.`id` = 35 LIMIT 1 D, [2020-03-29T06:35:46.875050 #29210] DEBUG -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] CACHE (0.0ms) SELECT `shops`.* FROM `shops` WHERE `shops`.`id` = 35 LIMIT 1 [["id", 35], ["LIMIT", 1]] D, [2020-03-29T06:35:46.878060 #29210] DEBUG -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] (2.7ms) BEGIN D, [2020-03-29T06:35:46.881737 #29210] DEBUG -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] Comment Load (2.7ms) SELECT `comments`.* FROM `comments` WHERE `comments`.`shop_id` = 35 D, [2020-03-29T06:35:46.885304 #29210] DEBUG -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] Like Load (2.8ms) SELECT `likes`.* FROM `likes` WHERE `likes`.`shop_id` = 35 D, [2020-03-29T06:35:46.888753 #29210] DEBUG -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] SQL (2.9ms) DELETE FROM `shops` WHERE `shops`.`id` = 35 D, [2020-03-29T06:35:46.894427 #29210] DEBUG -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] (5.3ms) COMMIT I, [2020-03-29T06:35:46.894886 #29210] INFO -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] No template found for ShopsController#destroy, rendering head :no_content I, [2020-03-29T06:35:46.895128 #29210] INFO -- : [4133cce2-cf00-4251-9920-0a69970fa8f4] Completed 204 No Content in 31ms (ActiveRecord: 22.0ms)
編集ボタン
I, [2020-03-29T06:40:08.010756 #29208] INFO -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] Started GET "/shops/36/edit" for 14.3.50.42 at 2020-03-29 06:40:08 +0000 I, [2020-03-29T06:40:08.011462 #29208] INFO -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] Processing by ShopsController#edit as HTML I, [2020-03-29T06:40:08.011538 #29208] INFO -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] Parameters: {"id"=>"36"} D, [2020-03-29T06:40:08.018090 #29208] DEBUG -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] User Load (2.8ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1 D, [2020-03-29T06:40:08.021525 #29208] DEBUG -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] Shop Load (2.8ms) SELECT `shops`.* FROM `shops` WHERE `shops`.`id` = 36 LIMIT 1 D, [2020-03-29T06:40:08.022087 #29208] DEBUG -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] CACHE (0.0ms) SELECT `shops`.* FROM `shops` WHERE `shops`.`id` = 36 LIMIT 1 [["id", 36], ["LIMIT", 1]] I, [2020-03-29T06:40:08.022758 #29208] INFO -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] Completed 406 Not Acceptable in 11ms (ActiveRecord: 5.6ms) F, [2020-03-29T06:40:08.023835 #29208] FATAL -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] F, [2020-03-29T06:40:08.023942 #29208] FATAL -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] ActionController::UnknownFormat (ShopsController#edit is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.): F, [2020-03-29T06:40:08.024050 #29208] FATAL -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] F, [2020-03-29T06:40:08.024191 #29208] FATAL -- : [e038f90c-3c83-4f30-b88d-a6d7e8ffcf2a] actionpack (5.0.7.2) lib/action_controller/metal/implicit_render.rb:56:in `default_render'
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。