Date driven timeline

Hi,

I am looking at developing an application that has a post type, currently just one, and I want them to be displayed on a timeline/dashboard. The reasoning behind this is that on the timeline each day you will see what posts were added on that day, and then navigate down to see other days. For example:

17 July 2014
Post 22
Post 23

16 July 2014
Post 21

15 July 2014
Post 20
Post 19

ect ect.

I am having trouble working out how this may be achieved. Can I go down the route of creating a scope for the queries, if so how will it display the date above the first post.

Any insight into how this may be achieved we be very much appreciated.

Please let me know if you need more info.

Hopefully I understood your question correctly. One approach could be to do the following:

@post_groupings_by_day = Post.all.group_by { |post| post.date_added }

This would create a multidimensional array like so:

[[17 July 2014, [Post 22, Post 23]], [16 July 2014, [Post 21]], etc..]

Then you can just use that to drive your view.

Hey @frank_west_iii that sounds like what I am after, cheers man. To me this means I could also get rid of the need for the timeline and amend the index action within post to use the @post_groupings_by_day object.

Does that sound right?

I really appreciated your help.

You could, not sure of the additional requirements. Timeline gains you some benefit of specifically having that concept separated from post which may provide value in the future, but also may not.