Montag, April 28, 2008

Upgrade to rails2

Yeah, since last week palabea runs on rails2 on production. The actual refactoring was painless and even the production deploy had just minor bugs. There are tiny changes coming with the upgrade - like empty parameters are now blank and not nil - which fell through our test coverage. So a quick look over all your controllers is needed if you want to avoid surprises in production.

Donnerstag, April 03, 2008

Adding parameters to routes

Routes are definitly one of the black holes in rails development. Most of the time you are dealing with standard configurations. You have to learn them, but there are not too many options you have.
But last time I wanted something special: to add an parameter to a url if a special route is called. We have /videos and we have /videos?lecture=true. Both are videos, share the same table and model, but they are treated differently in the GUI. So I thought definining a new route /lectures would be nice. I should call the same methods as for /videos but with a special parameter added. There is no way to do it. But hey I thought thats Ruby. What about adding a block, or override a special method. Then I started digging into the code. ... Wow, thats hot stuff, where to start? Jamis Buck tried but I couldn't figure out where and how to place my hook.
Finally I resignated and added a before_filter to the controller which does a regexp check against the request_uri. This does also the job, but I added code to the controller which is part of the routes logic, so really I dont like the solution. But it works fine for now.