I've been doing more playing with typo, this time trying to wrestle in a way to handle a default category for blog entries. In my old MT setup, I had a category that I used to resrtict entries on the front page (originally named 'Blog'), and I wanted to continue to use this functionality, since I imported all of my old MT entries.
Digging into the code, my first inclination was to modify the articles controller(app/controllers/articles_controller.rb), changing the index action here:
def index
@pages=Paginator.newself,Article.count,10,@params['page']
@articles=Article.find_all('published !=0','created_at DESC',@pages.current.to_sql)
end
to this:
def index
@pages=Paginator.newself,Article.count,10,@params['page']
@articles=Article.find_all('published !=0','created_at DESC',@pages.current.to_sql)
@articles=@articles.find_all{|art|art.categories.any?{|cat|cat.name=="blog"}}
end
Obviously, this is far from ideal. Now I'm hacking up the internal code of my blog software, and in a very ugly way at that. On top of all that, this completely breaks the nice pagination that I was previously getting for free.
Fortunately, there's a much cleaner solution. Open up that default routes file, config/routes.rb, and change the following default from this:
map.connect'',:controller=>'articles'
to this
map.connect'',:controller=>'articles',:action=>"category",:id=>"Blog"
Now I have nice default category filtering for my entries, and I don't have to do a terrible hack to make it work. Just a teeny-weeny little routing tweak.
I can live with that.