Re: polymorphic_url and namespaces

Sven Fuchs
Sun, 11 May 2008 10:09:19 -0000

> Sounds like we have a few motivated contributors here, looking forward
> to watching it take shape in irc :)

Ok, I''ve implemented what I believe is a sane option here:

http://github.com/svenfuchs/rails/commits/master/

There are a couple of things to discuss though and none of you (koz,
mislav) is on #rails-contrib right now so I thought I''d ask here
instead.

Most importantly, after storing the namespace option in the route and
then passing it back from Route#recognize_path where should it be
stored in the controller layer?

I first thought that the best option is to set it on the controller
instance. After studying the code more thoroughly I now think that
another sane option is to just store it in the params hash.

Storing it in the controller instance would require to

- either temporarily store it in the params hash in
Route#recognize_path and then delete if from there in
Dispatcher#handle_request or even ActionController::Base#process
(ugly, but doesn''t require to change the involved method apis that
pass the params hash)
- or change the return value apis of at least Route#recognize_path and
RouteSet#recognize to return something like [params, route] or
[params, namespace] (also noisy, but less ugly, also requires to
change lots of tests)

Storing it in the params hash would require the fewest changes
allover. We''d just stick the namespace to params in
Route#recognize_path and can then access that in polymorphic_url (and
everywhere else in the controller layer).

(Another option would be to store it in the Request object, but
there''s no similar information stored so far.)

I''ve opted for the last option for now, but of course that exposes
another key in the params hash. What do you think about that? Looking
at the existing keys like :controller and :action the additional
key :namespace would IMO make a lot sense here anyways because that''s
all stuff that''s defined in the routes.

Hope to catch any of you on IRC, please ping me :)