[typo] Fixing category & tag feeds

Scott Laird scott at sigkill.org
Mon Sep 5 09:13:58 EDT 2005


On Sep 5, 2005, at 6:04 AM, Aitor Garcia Rey wrote:

> Browsing the app/controllers/xml_controller.rb for integrate my  
> blog on a planet-like site (http://weblogs.javahispano.org/ 
> planet.do?rmik=tabbedmenu.planet) , I've found the by category & by  
> tag feeds are working on ascendant order, while - as the by article/ 
> tracback/comments feeds- the logic order is DESC.
>
> I'm real nuby XD and since I can't figure out the existence of a  
> ".sort_by_desc" method  I've simply patched  the source as :
>
> -- --- app/controllers/xml_controller.rb   (revision 629)
> +++ app/controllers/xml_controller.rb   (working copy)
> @@ -40,6 +40,7 @@
>        category = Category.find_by_permalink(params[:id])
>        @items = category.articles.sort_by {|a| a.created_at}.
>          reject {|a| a.published != 1 }.
> +        reverse!.
>          slice(0,config[:limit_rss_display])
>        @feed_title = "#{config[:blog_name]}: Category # 
> {category.name}"
>        @link = url_for({:controller => "articles", :action =>  
> "category", :id => category.permalink},
>
> ...and the same stuff for by tag feed.
>
> If someone could confirm that this is the best way to do it -surely  
> not :-D -, I would submit the [PATCH] ticket with the test etc.  
> Anyways it would be great to listen to others more experienced ruby  
> hackers a better way to patch this.

Thanks for catching this.  There are two other ways to change the  
order, and either one would probably be slightly better.

First, instead of 'reverse!' we could use 'reverse' (without the !)-- 
since we're relying on the output of reverse to pass on to slice, we  
don't need the '!' form of reverse.

Second, we could include a :order => 'created_at DESC' clause in the  
find_by_permalink method.  I *think* the find_by_* methods will  
take :order flags.  We should add a :limit clause at the same time.

Anyway, looking at the code, we're going to need to do a bit more,  
because this will leak unpublished articles; I'll probably create a  
class method in Category (and Tag) to handle all of this, so we can  
reuse it elsewhere.


Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/typo-list/attachments/20050905/d60c0e62/attachment.htm


More information about the Typo-list mailing list