diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb
index 3e56d2d..52b5f46 100644
--- a/app/controllers/tasks_controller.rb
+++ b/app/controllers/tasks_controller.rb
@@ -1,53 +1,34 @@
class TasksController < ApplicationController
- def index
- @project = Project.find(params[:project_id])
- @tasks = @project.tasks
- end
+ before_action :set_project
- def show
- @project = Project.find(params[:project_id])
- @task = @project.tasks.find(params[:id])
- end
+ def create
+ @task = @project.tasks.build(task_params)
- def new
- @project = Project.find(params[:project_id])
- @task = @project.tasks.new
- end
-
- def create
- @project = Project.find(params[:project_id])
- @task = @project.tasks.new(task_params)
- if @task.save
- redirect_to project_task_path(@project, @task)
+ if @task.save
+ respond_to do |format|
+ format.turbo_stream
+ format.html { redirect_to @project, notice: "Task created!" }
+ end
else
- render :new
+ respond_to do |format|
+ format.turbo_stream { render turbo_stream: turbo_stream.replace("new_task", partial: "tasks/form", locals: { project: @project, task: @task }) }
+ format.html { render "projects/show", status: :unprocessable_entity }
end
end
+ end
- def edit
- @project = Project.find(params[:project_id])
- @task = @project.tasks.find(params[:id])
- end
+ def destroy
+ @task = @project.tasks.find(params[:id])
+ @task.destroy
+ end
- def update
- @project = Project.find(params[:project_id])
- @task = @project.tasks.find(params[:id])
- if @task.update(task_params)
- redirect_to project_task_path(@project, @task)
- else
- render :edit
- end
- end
+ private
- def destroy
- @project = Project.find(params[:project_id])
- @task = @project.tasks.find(params[:id])
- @task.destroy
- redirect_to project_tasks_path(@project)
- end
+ def set_project
+ @project = Project.find(params[:project_id])
+ end
- private
- def task_params
- params.require(:task).permit(:title, :description, :status)
- end
+ def task_params
+ params.require(:task).permit(:title, :status)
+ end
end
diff --git a/app/helpers/tasks_helper.rb b/app/helpers/tasks_helper.rb
new file mode 100644
index 0000000..ce894d0
--- /dev/null
+++ b/app/helpers/tasks_helper.rb
@@ -0,0 +1,2 @@
+module TasksHelper
+end
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index 6c15d46..6951f83 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -10,3 +10,6 @@
} %>
<% end %>
+
+
+
<%= @project.description %>
-
+ <%= f.label :title %>
+ <%= f.text_field :title %>
+
+ <%= f.label :status %>
+ <%= f.select :status, Task.statuses.keys %>
+
- <%= task.label :title %>
- <%= task.text_field :title %>
- <% @project.tasks.each do |t| %>
- <% t.errors.full_messages_for(:title).each do |message| %>
-
<%= message %>
- <% end %> - <% end %> - - -
- <%= task.label :status %>
- <%= task.select :status, Task.statuses.keys %>
-
- <%= task.submit "Create Task" %> -
-<% end %> \ No newline at end of file diff --git a/test/controllers/projects_controller_test.rb b/test/controllers/projects_controller_test.rb new file mode 100644 index 0000000..4305777 --- /dev/null +++ b/test/controllers/projects_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ProjectsControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get projects_index_url + assert_response :success + end +end diff --git a/test/controllers/tasks_controller_test.rb b/test/controllers/tasks_controller_test.rb new file mode 100644 index 0000000..a60ed4a --- /dev/null +++ b/test/controllers/tasks_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class TasksControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end