Added complete button

This commit is contained in:
KaungKaung
2026-01-28 14:59:13 +06:30
parent 0f5d105be3
commit 7c9e164a9a
6 changed files with 55 additions and 16 deletions

View File

@@ -22,6 +22,16 @@ class TasksController < ApplicationController
@task.destroy
end
def complete
@task = @project.tasks.find(params[:id])
@task.update(status: "done")
respond_to do |format|
format.turbo_stream
format.html { redirect_to @project }
end
end
private
def set_project

View File

@@ -4,18 +4,23 @@
<turbo-frame id="tasks">
<ul id="tasks_list">
<% @project.tasks.each do |task| %>
<li id="<%= dom_id(task) %>">
<%= task.title %> (<%= task.status %>)
<%= link_to "Destroy", project_task_path(@project, task), data: {
turbo_method: :delete,
turbo_confirm: "Are you sure?"
} %>
</li>
<turbo-frame id="<%= dom_id(task) %>">
<li>
<%= task.title %> (<%= task.status %>)
<%= link_to "Destroy", project_task_path(@project, task), data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %>
<% unless task.status == "done" %>
<%= button_to "Complete", complete_project_task_path(@project, task), method: :patch, form: { data: { turbo_frame: dom_id(task) } } %>
<% end %>
</li>
</turbo-frame>
<% end %>
</ul>
</turbo-frame>
<turbo-frame id="new_task">
<br>
<h2>Add New Task</h2>
<%= render partial: "tasks/form", locals: { project: @project, task: Task.new } %>
</turbo-frame>

View File

@@ -0,0 +1,16 @@
<turbo-frame id="<%= dom_id(task) %>">
<li>
<%= task.title %> (<%= task.status %>)
<%= 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) } } %>
<% end %>
</li>
</turbo-frame>

View File

@@ -0,0 +1,10 @@
<%= turbo_stream.replace dom_id(@task) do %>
<li>
<%= @task.title %> (<%= @task.status %>)
<%= link_to "Destroy", project_task_path(@project, @task), data: {
turbo_method: :delete,
turbo_confirm: "Are you sure?"
} %>
</li>
<% end %>

View File

@@ -1,11 +1,5 @@
<%= turbo_stream.append "tasks_list" do %>
<li id="<%= dom_id(@task) %>">
<%= @task.title %> (<%= @task.status %>)
<%= link_to "Destroy", project_task_path(@project, @task), data: {
turbo_method: :delete,
turbo_confirm: "Are you sure?"
} %>
</li>
<%= render partial: "tasks/task", locals: { task: @task } %>
<% end %>
<%= turbo_stream.replace "new_task" do %>

View File

@@ -3,7 +3,11 @@ Rails.application.routes.draw do
root "projects#index"
resources :projects do
resources :tasks
resources :tasks do
member do
patch :complete
end
end
end