RubyonRailsでToDoアプリを作成しています。
scaffoldで一通り作成した後、編集をして作成しているのですが、
削除機能が機能しません。
削除ボタンを押しても、ブラウザに「The action 'destroy' could not be found for TasksController」というエラーが出てしまいます。
TasksControllerにはdestroyアクションを記述してあります。
どうすればいいでしょうか。
TasksController
1class TasksController < ApplicationController 2 before_action :set_task, only: [:show, :edit, :update, :destroy] 3 before_action :login_check, only: [:new, :edit, :update, :destroy, :index, :comp] 4 # GET /tasks 5 # GET /tasks.json 6 def index 7 @tasks = current_user.tasks.all 8 9 end 10 11def destroy 12 @task.destroy 13 @task = Task.find(params[:id]) 14 15 redirect_to '/tasks' ,notice: '削除しました' 16end 17 18 19 private 20 # Use callbacks to share common setup or constraints between actions. 21 def set_task 22 @task = Task.find(params[:id]) 23 end
HTML
1<p id="notice"><%= notice %></p> 2 3<h1>タスク一覧</h1> 4 5<table> 6 <thead> 7 <tr> 8 <th>タスク</th> 9 <th>カテゴリー</th> 10 <th>状況</th> 11 <th>期限</th> 12 <th colspan="3"></th> 13 </tr> 14 </thead> 15 16 <tbody> 17 <% @tasks.each do |task| %> 18 <% if task.status == '未完了' %> 19 20 21 <tr> 22 <td><%= task.title %></td> 23 <td><%= task.category %></td> 24 <td><%= task.status %></td> 25 <td><%= task.due_date %></td> 26 27 <td><%= link_to '編集', edit_task_path(task) %></td> 28 <td><%= link_to '削除', task, method: :delete, :onclick => "return confirm('削除しますか?')" %></td> 29 </tr> 30 <% end %> 31 <% end %> 32 </tbody> 33</table>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。