Topic: What's the right Rails idiom for dealing with contained objects
I've been working on the administration panel of my application and I've gone through about 3-4 different approaches to controller organization/url space. (This is related to by earlier thread on this forum titled Control Panels and large number of contained models).
In my case, the user selects/creates a competition and then starts to configure it. This includes establishing a list of levels, styles, costs, and events. The selected competition object (or its id) must remain available through a long series of operations. Now, in the non-admin area of the site I basically need some human readable form of the competition name in the URL (often suitably abbreviated). I'm using to_param to handle this and that works well. The non-admin area, however is rather linear/wizard-like and as a result the controller/views are more complex and not as model focused as the admin area.
So I was going to initially piggy-back on my to_param in the admin section as well, so I would have urls like
This was "working" and I like the format, however, it seems to be a minor disaster when it comes to route generation and most testing tools expectations. All url generating functions need to have the :short_name=>@competition.short_name appended to the parameter list for it to inject it into the URL; and its mighty un-DRY.
Now I could stick the competition_id into the session and avoid this, but it doesn't get rid of the problem as there are "landing" pages where I'll have to use the human readable URL, but it would solve my current problem.
Is there an easy way to handle this? There's a ton of functions that would need to be overridden in an intermediate class between my Controllers and ActionController::Base and not all of them are actually part of AC::Base -- named routes, form_tag helpers, etc.
Its somewhat similar to the AR::Base's with_scope... is there something similar for AC::Base?