diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb
new file mode 100644
index 0000000..2d70cab
--- /dev/null
+++ b/app/controllers/todos_controller.rb
@@ -0,0 +1,51 @@
+class TodosController < ApplicationController
+ before_action :set_todo, only: [:edit, :update, :destroy]
+
+ def new
+ @todo = Todo.new
+ end
+
+ def create
+ @todo = Todo.new(todo_params)
+ if @todo.save
+ redirect_to @todo.learning_goal, notice: t(".created")
+ else
+ render :new, status: :unprocessable_entity
+ end
+ end
+
+ def edit ; end
+
+ def update
+ if @todo.update(todo_params)
+ redirect_to @todo.learning_goal, notice: t(".updated")
+ else
+ render :edit, status: :unprocessable_entity
+ end
+ end
+
+ def destroy
+ learning_goal = @todo.learning_goal
+ if @todo.destroy
+ redirect_to learning_goal, notice: t(".deleted")
+ else
+ render :edit, status: :unprocessable_entity
+ end
+ end
+
+ private
+
+ def set_todo
+ @todo = Todo.find(params[:id])
+ end
+
+ def todo_params
+ params.require(:todo).permit(
+ :learning_goal_id,
+ :description,
+ :done,
+ :title,
+ :due,
+ )
+ end
+end
diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb
new file mode 100644
index 0000000..65ab195
--- /dev/null
+++ b/app/helpers/todos_helper.rb
@@ -0,0 +1,2 @@
+module TodosHelper
+end
diff --git a/app/models/learning_goal.rb b/app/models/learning_goal.rb
index bab7dec..554aaac 100644
--- a/app/models/learning_goal.rb
+++ b/app/models/learning_goal.rb
@@ -1,5 +1,8 @@
class LearningGoal < ApplicationRecord
belongs_to :user
+ has_many :todos
+ has_and_belongs_to_many :tags
+ accepts_nested_attributes_for :tags
has_rich_text :description
has_rich_text :retrospective
@@ -7,12 +10,9 @@ class LearningGoal < ApplicationRecord
validates :title, presence: true
- has_and_belongs_to_many :tags
- accepts_nested_attributes_for :tags
-
def microposts
microposts = Micropost.none
tags.each { |tag| microposts = microposts.or(tag.microposts) }
- microposts
+ microposts.uniq
end
end
diff --git a/app/models/todo.rb b/app/models/todo.rb
index af053c1..3b66da3 100644
--- a/app/models/todo.rb
+++ b/app/models/todo.rb
@@ -1,4 +1,6 @@
class Todo < ApplicationRecord
belongs_to :learning_goal
validates :done, inclusion: { in: [true, false] }
+ has_rich_text :description
+ has_one :user, through: :learning_goal
end
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 8d4e11f..c1ba737 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -22,6 +22,7 @@
<%= link_to t(".microposts"), microposts_path %>
<% if logged_in? %>
<%= link_to t(".diary_entries"), diary_entries_path %>
+ <%= link_to t(".learning_goals"), learning_goals_path %>
<%= link_to t(".profile"), user_path(current_user) %>
<%= link_to t(".log_out"), log_out_path, data: { turbo_method: :delete } %>
<% end %>
diff --git a/app/views/learning_goals/index.html.erb b/app/views/learning_goals/index.html.erb
index 83821ad..ac3a3a3 100644
--- a/app/views/learning_goals/index.html.erb
+++ b/app/views/learning_goals/index.html.erb
@@ -1,6 +1,7 @@
<%= t(".learning_goals") %>
<%= link_to t(".new"), new_learning_goal_path if logged_in? %>
+<%= link_to t(".new_todo"), new_todo_path if logged_in? %>
<% if @learning_goals.empty? %>
<%= t(".empty") %>
diff --git a/app/views/learning_goals/show.html.erb b/app/views/learning_goals/show.html.erb
index 71507e5..d5b3241 100644
--- a/app/views/learning_goals/show.html.erb
+++ b/app/views/learning_goals/show.html.erb
@@ -9,6 +9,13 @@
<%= @learning_goal.retrospective %>
<% end %>
+ <%= t(".todos") %>
+
+ <% @learning_goal.todos.each do |todo| %>
+ - <%= render todo %>
+ <% end %>
+
+
<%= t(".tags") %>
<% @learning_goal.tags.each do |tag| %>
diff --git a/app/views/todos/_form.html.erb b/app/views/todos/_form.html.erb
new file mode 100644
index 0000000..90cbfbb
--- /dev/null
+++ b/app/views/todos/_form.html.erb
@@ -0,0 +1,18 @@
+<%= form_with model: @todo, id: "todo_form" do |f| %>
+ <%= title %>
+
+ <%= f.text_field :title, placeholder: t(".title") %>
+
+ <%= f.label :learning_goal %>
+ <%= f.collection_select :learning_goal_id, LearningGoal.all, :id, :title %>
+
+ <%= f.rich_text_area :description %>
+
+ <%= f.label :due %>
+ <%= f.date_field :due %>
+
+ <%= f.label :done %>
+ <%= f.check_box :done %>
+
+ <%= f.submit button_text %>
+<% end %>
diff --git a/app/views/todos/_todo.html.erb b/app/views/todos/_todo.html.erb
new file mode 100644
index 0000000..61de345
--- /dev/null
+++ b/app/views/todos/_todo.html.erb
@@ -0,0 +1,10 @@
+
+ checked
+ <% end %>>
+<%= todo.title %>
+<%= todo.description %>
+<% if todo.user == current_user %>
+ <%= link_to t(".edit"), edit_todo_path(todo) %>
+ <%= link_to t(".delete"), todo, data: { turbo_method: :delete, turbo_confirm: t(".confirm") } %>
+<% end %>
diff --git a/app/views/todos/edit.html.erb b/app/views/todos/edit.html.erb
new file mode 100644
index 0000000..7bde9d6
--- /dev/null
+++ b/app/views/todos/edit.html.erb
@@ -0,0 +1,10 @@
+<% @title = t(".edit") %>
+
+<%= render partial: "form",
+ locals: {
+ user: @user,
+ button_text: t(".edit"),
+ title: t(".edit"),
+ } %>
+
+<%= link_to t(".delete"), @todo, data: { turbo_method: :delete, turbo_confirm: t(".confirm") } %>
diff --git a/app/views/todos/new.html.erb b/app/views/todos/new.html.erb
new file mode 100644
index 0000000..e4e2ca0
--- /dev/null
+++ b/app/views/todos/new.html.erb
@@ -0,0 +1,8 @@
+<% @title = t(".create") %>
+
+<%= render partial: "form",
+ locals: {
+ user: @user,
+ button_text: t(".create"),
+ title: t(".create"),
+ } %>
diff --git a/config/locales/controllers/todos/en.yml b/config/locales/controllers/todos/en.yml
new file mode 100644
index 0000000..d6aad56
--- /dev/null
+++ b/config/locales/controllers/todos/en.yml
@@ -0,0 +1,5 @@
+en:
+ todos:
+ created: Successfully created todo
+ updated: Successfully updated todo
+ deleted: Successfully deleted todo
diff --git a/config/locales/views/layouts/application.yml b/config/locales/views/layouts/application.yml
index 4bbd3c9..48c7e1f 100644
--- a/config/locales/views/layouts/application.yml
+++ b/config/locales/views/layouts/application.yml
@@ -10,3 +10,4 @@ en:
blog_posts: Blog
microposts: μposts
diary_entries: Diary
+ learning_goals: Learning Goals
diff --git a/config/locales/views/learning_goals/en.yml b/config/locales/views/learning_goals/en.yml
index 1897392..218f075 100644
--- a/config/locales/views/learning_goals/en.yml
+++ b/config/locales/views/learning_goals/en.yml
@@ -4,6 +4,7 @@ en:
learning_goals: Learning Goals
empty: You have no learning goals yet.
new: New learning goal
+ new_todo: New todo
new:
create: Create learning goal
edit:
@@ -19,4 +20,5 @@ en:
description: Description
retrospective: Retrospective
tags: Tags
+ todos: Todos
related_microposts: Related μposts
diff --git a/config/locales/views/todos/en.yml b/config/locales/views/todos/en.yml
new file mode 100644
index 0000000..42a346d
--- /dev/null
+++ b/config/locales/views/todos/en.yml
@@ -0,0 +1,14 @@
+en:
+ todos:
+ new:
+ create: Create todo
+ edit:
+ edit: Edit todo
+ delete: Delete todo
+ confirm: Are you sure you want to delete this todo?
+ form:
+ title: Title
+ todo:
+ edit: Edit todo
+ delete: Delete todo
+ confirm: Are you sure you want to delete this todo?
diff --git a/config/routes.rb b/config/routes.rb
index b8292cf..2868fbf 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -16,6 +16,7 @@ Rails.application.routes.draw do
resources :learning_goals
resources :microposts
resources :tags, only: [:index, :show]
+ resources :todos, only: [:new, :create, :edit, :update, :destroy]
resources :diary_entries, except: [:destroy]
get "up" => "rails/health#show", as: :rails_health_check
diff --git a/test/controllers/todos_controller_test.rb b/test/controllers/todos_controller_test.rb
new file mode 100644
index 0000000..f53fe65
--- /dev/null
+++ b/test/controllers/todos_controller_test.rb
@@ -0,0 +1,7 @@
+require "test_helper"
+
+class TodosControllerTest < ActionDispatch::IntegrationTest
+ # test "the truth" do
+ # assert true
+ # end
+end