Add references between projects and todos
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled

This commit is contained in:
2025-10-27 13:48:15 +01:00
parent 871377a90b
commit 9f42deee95
8 changed files with 47 additions and 2 deletions

View File

@@ -65,6 +65,6 @@ class TodosController < ApplicationController
# Only allow a list of trusted parameters through.
def todo_params
params.expect(todo: [ :name, :description ])
params.expect(todo: [ :name, :description, :completed, :priority, :project_id ])
end
end

View File

@@ -1,3 +1,4 @@
class Project < ApplicationRecord
has_many :todos, dependent: :destroy
validates :name, presence: true
end

View File

@@ -1,2 +1,3 @@
class Todo < ApplicationRecord
belongs_to :project
end

View File

@@ -1,4 +1,9 @@
<h1><%= @project.name %></h1>
<% @project.todos.each do |todo| %>
<li><%= link_to todo.name, todo_path(todo) %></li>
<% end %>
<%= link_to "Edit", edit_project_path %>
<%= button_to "Delete", project_path, method: :delete %>
<%= link_to "Back", projects_path %>

View File

@@ -21,6 +21,21 @@
<%= form.textarea :description %>
</div>
<div>
<%= form.label :completed %>
<%= form.check_box :completed %>
</div>
<div>
<%= form.label :priority %>
<%= form.number_field :priority %>
</div>
<div>
<%= form.label :project_id %>
<%= form.collection_select :project_id, Project.all, :id, :name, prompt: "Select a project" %>
</div>
<div>
<%= form.submit %>
</div>

View File

@@ -9,4 +9,18 @@
<%= todo.description %>
</div>
<div>
<strong>Completed:</strong>
<%= todo.completed %>
</div>
<div>
<strong>Priority:</strong>
<%= todo.priority %>
</div>
<div>
<strong>Project:</strong>
<%= link_to todo.project.name, project_path(todo.project) %>
</div>
</div>