[typo] ticket #13 - add Archive articles by month (I hope this is what it means!)

Stuart Smith stuart.smith at smsconsulting.wanadoo.co.uk
Wed Apr 13 17:51:36 EDT 2005


Selecting created_at returns both the date and the time of the article;
without some formatting at the SQL select level the grouping/parsing of
the returned data set has to be done somewhere else. 

I take it that this discussion infers that ALL SQL statements must be
able to be executed by ALL supported DB backends? There must be some way
to provide DB specific queries as some sort of configuration parameters?
[As I stated earlier, the SQL used to construct the DB depends very much
on the DB backend and everyone seems quite happy to run specific scripts
to support this].

Is it possible to handle date formatting at the DB Adaptor level?

Stuart



On Wed, 2005-04-13 at 17:39 -0400, Tobias Luetke wrote:
> Personally i must confess that I'm surprised that anyone would want
> this feature.
> 
> I always thought it was pretty useless on other blogs. 
> 
> That being said thats a good way to do it Vince
> 
> On 4/13/05, Vince Hodges <vhodges at shaw.ca> wrote:
> > Regarding the db specific sql...How about something like this (not
> > tested, just off the top of my head!):
> > 
> > app/views/shared/_archives.rhtml        [new file]
> > <b>Archives</b><br/>
> > <% for archive in archives -%>
> >    <%= link_to archive.created_at.strftime("%B %Y"),
> >    "/articles/"+archive.created_at.strftime("%Y/%m") %><br/>
> > <% end -%>
> > 
> > app/models/article.rb           [ new function ]
> > def self.find_dates()
> >     @archives=Article.find_by_sql(["SELECT distinct created_at from
> >         articles ORDER by created_at"])
> > end
> > 
> > The calls to strftime could (and probably should) go into a helper.
> > Formatting data for display should go into the view, not the
> > persistance layer IMO.
> > 
> > I was thinking that it would be cool if it worked something like this:
> > 
> > - Show a set of controls for navigating years (increment,
> > decrement and the year itself).
> > - And as the year changes, make an ajax call to get the months for the
> > selected year that contain posts and update the display
> > accordingly. (maybe faded text for months that have no posts)
> > 
> > 
> > Vince
> > 
> > 
> > On 20:10, Wed 13 Apr 05, Stuart Smith wrote:
> > > Hi Tobias, I took on board your comment and have reduced the solution to
> > > this:
> > > ###########################################################################
> > >
> > > app/views/shared/_archives.rhtml        [new file]
> > >
> > >
> > > <b>Archives</b><br/>
> > > <% for archive in archives -%>
> > > <%= link_to archive.dispdate, "/articles/"+archive.date %><br/>
> > > <% end -%>
> > >
> > >
> > > app/views/layouts/articles.rhtml           [add code nr categorylist]
> > >
> > >   <%= archivelist %>
> > >   <br/>
> > >
> > >
> > >
> > > app/models/article.rb           [ new function ]
> > >
> > >   def self.find_dates()
> > >     @archives=Article.find_by_sql(["SELECT distinct date_format
> > > (created_at, '%%M %%Y') dispdate, date_format(created_at, '%%Y/%%m')
> > > date from articles ORDER by created_at "])
> > >   end
> > >
> > >
> > > app/helpers/application_helper.rb       [ new function ]
> > >
> > >   def archivelist()
> > >     archives = Article.find_dates()
> > >     render_partial("shared/archives", archives)
> > >   end
> > >
> > > ############################################################################
> > >
> > > This is now a lot simpler than before but still contains some MySql
> > > specific date formatting.
> > >
> > > I would appreciate any comments from anyone.
> > >
> > > regards
> > >
> > > Stuart Smith
> > >
> > >
> > >
> > > On Tue, 2005-04-12 at 17:04 -0400, Tobias Luetke wrote:
> > > > Typo supports this already.
> > > >
> > > > http://blog.leetsoft.com/articles/2005/
> > > > http://blog.leetsoft.com/articles/2005/03/
> > > > http://blog.leetsoft.com/articles/2005/03/28/
> > > >
> > > > On Apr 12, 2005 4:21 PM, Stuart Smith
> > > > <stuart.smith at smsconsulting.wanadoo.co.uk> wrote:
> > > > > I misunderstood the database dependency issues; I just assumed that
> > > > > since an ISP/host would run typo against a specific persistent storage
> > > > > mechanism then a specific version of archive.rb would be installed on
> > > > > the target system. I just saw this as an extension of the multiple SQL
> > > > > files to create the initial schema for a specific vendor db.
> > > > >
> > > > > It would be interesting to see what others make of the problem regarding
> > > > > vendor specific SQL statements. There are companies that make a living
> > > > > from 'middleware' to allow the coder to write non-specific SQL (e.g.
> > > > > RogueWave had something called dbtools.h that I used a long time ago but
> > > > > that was a real 'pain in the ass' to use).
> > > > >
> > > > > Thanks
> > > > >
> > > > > Stuart
> > > > >
> > > > >
> > > > > > > app/models/archive.rb
> > > > > > >
> > > > > > > class Archive < ActiveRecord::Base
> > > > > > >
> > > > > > >   has_many :articles
> > > > > > >
> > > > > > >   def self.find_dates()
> > > > > > >     @archives=Article.find_by_sql(["SELECT distinct date_format
> > > > > > > (created_at, '%%M %%Y') date from articles ORDER by created_at "])
> > > > > > >   end
> > > > > > >
> > > > > > > end
> > > > > > >
> > > > >
> > > > > _______________________________________________
> > > > > Typo-list mailing list
> > > > > Typo-list at rubyforge.org
> > > > > http://rubyforge.org/mailman/listinfo/typo-list
> > > > >
> > > >
> > > >
> > >
> > > _______________________________________________
> > > Typo-list mailing list
> > > Typo-list at rubyforge.org
> > > http://rubyforge.org/mailman/listinfo/typo-list
> > _______________________________________________
> > Typo-list mailing list
> > Typo-list at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/typo-list
> > 
> 
> 



More information about the Typo-list mailing list