Articles tagged with: routing

Routing parameters with a dot

Posted by Andreas on Tuesday, May 05, 2009 at 07:35 (CEST)

Last week I received an interesting bug report for an application I’m working on at the office. It has a controller with an index action that displays a list of items which can be filtered by tags. A tester reported that every time he chooses to filter the list by a tag that contains a dot, the site returns an error. First this seems strange since tags with a dot worked perfectly fine in tests.

But after digging deeper, I found a surprising reason for this strange error: To make URLs look nicer, I defined an extra route like this:

1 map.things 'things/:tag', :controller => 'things', :action => 'index',
2   :tag => nil

The intention was, to have /things/foo instead of /things&tag=foo as the URL. This actually worked fine – except for cases when the tag contained a dot.

Read more »

Sharing controllers and views with polymorphic resources

Posted by Andreas on Friday, May 16, 2008 at 08:26 (CEST)

A while ago I faced a problem with controllers for nested resources I wanted to reuse in different contexts (polymorphic resources). For example, I had a simple Todo model that is used to store tasks that have to be done. Having multiple users which are organized in teams, the goal was to have user-specific (personal) todos and team-specific todos. Obviously, both kind of todos could be handled exactly the same way (same controller, same views) – except that the context differs.

So here’s a way to use a single controller for a polymorphic resource.

Read more »