From 658bc90ed75392e71619602428b342014f823c32 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Sat, 6 Jan 2024 11:17:36 +0000 Subject: [PATCH] Show related microposts on learning goals --- app/models/learning_goal.rb | 6 ++++++ app/views/learning_goals/show.html.erb | 12 +++++++++++- config/locales/views/learning_goals/en.yml | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/learning_goal.rb b/app/models/learning_goal.rb index f818af9..0881b08 100644 --- a/app/models/learning_goal.rb +++ b/app/models/learning_goal.rb @@ -8,4 +8,10 @@ class LearningGoal < ApplicationRecord 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 + end end diff --git a/app/views/learning_goals/show.html.erb b/app/views/learning_goals/show.html.erb index 798d5cf..71507e5 100644 --- a/app/views/learning_goals/show.html.erb +++ b/app/views/learning_goals/show.html.erb @@ -1,4 +1,5 @@
+ <%= link_to t(".edit"), edit_learning_goal_path(@learning_goal) if @learning_goal.user == current_user %>

<%= @learning_goal.title %>

<%= @learning_goal.starts_on %>-<%= @learning_goal.ends_on %>

<%= t(".description") %>

@@ -7,5 +8,14 @@

<%= t(".retrospective") %>

<%= @learning_goal.retrospective %>

<% end %> - <%= link_to t(".edit"), edit_learning_goal_path(@learning_goal) if @learning_goal.user == current_user %> + +

<%= t(".tags") %>

+ + +

<%= t(".related_microposts") %>

+

<%= render @learning_goal.microposts %>

diff --git a/config/locales/views/learning_goals/en.yml b/config/locales/views/learning_goals/en.yml index 45686e9..1897392 100644 --- a/config/locales/views/learning_goals/en.yml +++ b/config/locales/views/learning_goals/en.yml @@ -18,3 +18,5 @@ en: edit: Edit description: Description retrospective: Retrospective + tags: Tags + related_microposts: Related μposts