From e3da79930c0e2a177123394e4bc6f33b33aeb08d Mon Sep 17 00:00:00 2001 From: KaungKaung Date: Wed, 28 Jan 2026 15:27:17 +0630 Subject: [PATCH] Render 'complete' button only if the task's status is not 'done'. --- app/controllers/tasks_controller.rb | 23 ++++++++++++++++------- app/views/tasks/_task.html.erb | 17 ++++++++--------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index 203770d..b4d7211 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -18,19 +18,28 @@ class TasksController < ApplicationController end def destroy - @task = @project.tasks.find(params[:id]) + @task = @project.tasks.find_by(id: params[:id]) + return unless @task + + task_dom_id = "task_#{@task.id}" @task.destroy + + respond_to do |format| + format.turbo_stream { render turbo_stream: turbo_stream.remove(task_dom_id) } + format.html { redirect_to @project } + end end + def complete - @task = @project.tasks.find(params[:id]) - @task.update(status: "done") + @task = @project.tasks.find(params[:id]) + @task.update(status: "done") - respond_to do |format| - format.turbo_stream - format.html { redirect_to @project } + respond_to do |format| + format.turbo_stream + format.html { redirect_to @project } + end end -end private diff --git a/app/views/tasks/_task.html.erb b/app/views/tasks/_task.html.erb index 77098b5..750ef9e 100644 --- a/app/views/tasks/_task.html.erb +++ b/app/views/tasks/_task.html.erb @@ -2,15 +2,14 @@
  • <%= task.title %> (<%= task.status %>) - <%= link_to "Destroy", project_task_path(task.project, task), data: { - turbo_method: :delete, - turbo_confirm: "Are you sure?" - } %> + <%= link_to "Destroy", project_task_path(task.project, task), + data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %> - <% unless task.status == "completed" %> - <%= button_to "Complete", complete_project_task_path(task.project, task), - method: :patch, - form: { data: { turbo_frame: dom_id(task) } } %> + <% unless task.status == "done" %> + <%= button_to "Complete", + complete_project_task_path(task.project, task), + method: :patch, + form: { data: { turbo_frame: dom_id(task) } } %> <% end %>
  • - + \ No newline at end of file