Does anyone know how best to create a list of links that will sort
objects by the month in which they were created, and automatically add
months as time goes on?
I have a method that can find the objects created on a certain day,
month, or year, based on url parameters. My question is how to
automatically generate the links that will pass my method the correct
parameters, based on the current date, and stopping listing at some
arbitrary date in the past (say May 2006).
I’m trying to mimic a typical blog-style archive, so if someone can
advise for an easier way to do that, that would be cool, too.
Does anyone know how best to create a list of links that will sort
objects by the month in which they were created, and automatically add
months as time goes on?
I have a method that can find the objects created on a certain day,
month, or year, based on url parameters. My question is how to
automatically generate the links that will pass my method the correct
parameters, based on the current date, and stopping listing at some
arbitrary date in the past (say May 2006).
I’m trying to mimic a typical blog-style archive, so if someone can
advise for an easier way to do that, that would be cool, too.
That’s not exactly what I need. I’d like a list of link such as this:
August 2007
July 2007
June 2007
…
to be generated automatically, depending on the current date.
For instance, once October is here, a link titled ‘September 2007’
will be added to the top of the list.
Each link in this list should simply have a URL that reflects its year
and month, e.g.
/blog/archive/2007/09
, the parameters of which (year and month) I can handle in a
controller method that finds posted in a given month, based on the
‘created_at’ date value.
So, instead of looping over the pages, as in your example, I’d like to
loop over the months since an arbitrary month in the past, e.g. June
2006.