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.
Donnerstag, April 03, 2008
Abonnieren
Kommentare zum Post (Atom)
Keine Kommentare:
Kommentar veröffentlichen