My timeline page showcases dates based on time stamps from activities I've created using the Public Activity Rails gem. Here's an example:
https://i.sstatic.net/8qAOw.jpg
In the example, you can see multiple dates displayed on the left in green. These dates are extracted from the created_at timestamps of the activities and presented in a user-friendly format.
I want to prevent duplicates from appearing. For instance, if there are multiple June 3rd dates, I only want to display it once.
Here is the HTML for date elements (displayed in a loop):
<li class="time-label">
<span class="bg-red">
<%= activity_date(activity) %>
</span>
</li>
Ruby Method used to format the date:
def activity_date(activity)
local_date(activity.created_at)
end
I was considering using a conditional statement either in Ruby or JavaScript to prevent duplicate dates from being displayed. Any suggestions?