Will it speed up?

I have released new RNS version (0.251). From user perspective, there should be no difference in functionality. Site should be much more faster, since I have implemented caching in RNS code (fragment caching to be exact).

After few days I will post here some numbers, how rendering times have changed. I hope it will be now faster ;)))

Acts As Taggable gem and MySQL duplicate key

I was using acts_as_taggable DHH’s plugin. But I have moved to gem based one. After changing my database scheme and making code changes I ran across issue. When I was updating routes with tags ActiveRecord have dumped following error:
ActiveRecord::StatementInvalid (Mysql::Error: Duplicate entry '9' for key 1: INSERT INTO routes_tags (`tag_id`, `id`, `route_id`) VALUES (9, 9, 46)):

I was digging two nights and… long story short – there has to be no primary index on table holding bindings between tags and objects (here: routes_tags table).

Route tagging

This morning I have released to public next RNS version (0.241). This is rather major update – routes can be tagged (using Rails act_as_taggable plugin), browsed by tags, routes can be also browsed by user owning them.

Go and check new features. When route is displayed, owner name is link to page with all routes from this user, tags on this page are also links to pages with routes by tag.

Now I need to add more search and browse features, RSS feed with new routes and comments to users/routes. And at this stage I plan to slow down with RNS development.

As for now for this site I have devoted something like 90 hours of work (80 in 2006 and 10 in this month). Well, again I’m impressed how Rails makes rapid development possible… This is specially true when most of this hours it was me learning JavaScript. So I can say now I would need only 50 hour of work, or something like this to build similar site.

Helpers available both in controller and templates

With famous DRY, I have written a bunch of common checks from RNS to some helpers methods. And I have to find some way to access them both from templates (RHTML) and controllers.

Rails provides two places to hold common helpers. First is app/controllers/application.rb, parent for all controllers. Methods defined in this class will be accessible for all controllers in Your application. Second one place is app/helpers/application_helper.rb. Methods defined there will be accessible for all RHTML templates.

But I see no simple way to write this in one place. Well it could be placed somewhere in lib directory and included by environments.rb, but I’m not sure if changes in such code would be automatically reloaded in development mode.

Methods from controllers can be accessed from template via controller variable (like this: controller.isOwner(@route)), but this is too verbose. So for now I use following approach – I define real code in ApplicationController (app/controllers/application.rb) and in appplication_helper.rb I define simple wrapper for each method I have defined in ApplicationController:

def isOwner(rt)
   controller.isOwner(rt)
end