前提・実現したいこと
一覧ページにあるゴミ箱アイコンや詳細ページにある削除ボタンを押して削除機能を実装したいのですが削除されません。
一覧ページある削除ボタンを押すと詳細ページに飛んでしまいます。
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
ruby
1works_controller.rb 2class WorksController < ApplicationController 3 before_action :set_work, only: [:edit, :show, :update, :destroy] 4 5 def index 6 @works = Work.all.order('created_at DESC') 7 end 8 9 def new 10 @work = Work.new 11 end 12 13 def create 14 @work = Work.new(work_params) 15 if @work.save 16 redirect_to works_path 17 else 18 render :new 19 end 20 end 21 22 def show 23 end 24 25 def destroy 26 @work.destroy 27 redirect_to works_path 28 end 29 30 def edit 31 end 32 33 def update 34 if @work.update(work_params) 35 redirect_to works_path 36 else 37 render :edit 38 end 39 end 40 41 private 42 43 def work_params 44 params.permit(:cliant_name, :job_description, :calendar, :work_place, :price).merge(user_id: current_user.id) 45 end 46 47 def set_work 48 @work = Work.find(params[:id]) 49 end 50end
ruby
1show.html.erb 2<div class="wrapper"> 3 <div class="side-bar"> 4 <%= render "side_bar" %> 5 </div> 6 <div class="chat"> 7 <div class="main"> 8 <div class="page-header"> 9 <h1>詳細</h1> 10 </div> 11 <div class="panel panel-default"> 12 <div class="panel-heading"> 13 <h1 class="panel-title">顧客</h1> 14 </div> 15 <div class="panel-body"> 16 <h2><%= @work.cliant_name %></h2> 17 </div> 18 <div class="panel-heading"> 19 <h1 class="panel-title">仕事内容</h1> 20 </div> 21 <div class="panel-body"> 22 <h2><%= @work.job_description %></h2> 23 </div> 24 <div class="panel-heading"> 25 <h1 class="panel-title">日付</h1> 26 </div> 27 <div class="panel-body"> 28 <h2><%= @work.calendar %></h2> 29 </div> 30 <div class="panel-heading"> 31 <h1 class="panel-title">場所</h1> 32 </div> 33 <div class="panel-body"> 34 <h2><%= @work.work_place %></h2> 35 </div> 36 <div class="panel-heading"> 37 <h1 class="panel-title">金額</h1> 38 </div> 39 <div class="panel-body"> 40 <h2><%= @work.price %></h2> 41 </div> 42 </div> 43 <button type="button" class="btn btn-secondary btn-lg"> 44 <%= link_to "削除", work_path(@work.id), method: :delete, class:"back" %> 45 </button> 46 <button type="button" class="btn btn-secondary btn-lg"> 47 <%= link_to "戻る", works_path, class: "back" %> 48 </button> 49 </div> 50 </div> 51</div> 52 53
ruby
1_work.html.erb 2<div class="message"> 3 <div class="upper-message"> 4 <div class="message-user"> 5 <div class="col-sm-4"> 6 <div class="panel panel-success"> 7 <div class="panel-heading"><%= link_to work.calendar, work_path(work.id) %></div> 8 <div class="panel-body"> 9 <%= work.cliant_name %> 10 <%= link_to edit_work_path(work.id) do %> 11 <span class="fas fa-edit"></span> 12 <% end %> 13 <%= link_to work_path(work.id), method: :delete do %> 14 <span class="fas fa-trash-alt"></span> 15 <% end %> 16 </div> 17 </div> 18 </div> 19 </div> 20 </div> 21</div>
ruby
1rails routes 2 Prefix Verb URI Pattern Controller#Action 3 new_user_session GET /users/sign_in(.:format) devise/sessions#new 4 user_session POST /users/sign_in(.:format) devise/sessions#create 5 destroy_user_session GET /users/sign_out(.:format) devise/sessions#destroy 6 new_user_password GET /users/password/new(.:format) devise/passwords#new 7 edit_user_password GET /users/password/edit(.:format) devise/passwords#edit 8 user_password PATCH /users/password(.:format) devise/passwords#update 9 PUT /users/password(.:format) devise/passwords#update 10 POST /users/password(.:format) devise/passwords#create 11 cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel 12 new_user_registration GET /users/sign_up(.:format) devise/registrations#new 13 edit_user_registration GET /users/edit(.:format) devise/registrations#edit 14 user_registration PATCH /users(.:format) devise/registrations#update 15 PUT /users(.:format) devise/registrations#update 16 DELETE /users(.:format) devise/registrations#destroy 17 POST /users(.:format) devise/registrations#create 18 root GET / users#index 19 users GET /users(.:format) users#index 20 edit_user GET /users/:id/edit(.:format) users#edit 21 user PATCH /users/:id(.:format) users#update 22 PUT /users/:id(.:format) users#update 23 works GET /works(.:format) works#index 24 POST /works(.:format) works#create 25 new_work GET /works/new(.:format) works#new 26 edit_work GET /works/:id/edit(.:format) works#edit 27 work GET /works/:id(.:format) works#show 28 PATCH /works/:id(.:format) works#update 29 PUT /works/:id(.:format) works#update 30 DELETE /works/:id(.:format) works#destroy
ruby
1routes.rb 2Rails.application.routes.draw do 3 devise_for :users 4 root to: "users#index" 5 resources :users, only: [:index,:edit, :update] 6 resources :works 7end 8
試したこと
コントローラーのdestroyアクションやpathを確認してみたのですが、原因がわかりません。
補足情報(FW/ツールのバージョンなど)
ruby '2.6.5'
rails 6.0.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/12/20 10:03
2021/12/21 00:40
2021/12/21 00:53
2021/12/21 01:50 編集
2021/12/21 01:57
2021/12/21 02:09 編集
2021/12/21 03:15
2021/12/21 03:25
2021/12/21 05:31
2021/12/21 08:42
2021/12/21 10:59