Missing :resource_path for map.resources

3 views
Skip to first unread message

Alexander Hoth

unread,
Feb 12, 2009, 6:08:19 PM2/12/09
to resources_controller

Hi there,

I am building an application with I18n support and
resources_controller. The current locale is determined by the first
element of the path. I am using Sven Fuchs´ routing-filter plugin to
accomplish something like this:


http://www.example.com/items # I18n.locale = I18n.default_locale
http://www.example.com/de/items # I18n.locale = :de

The ItemsController is mapped in the routes.rb file

map.resources :items

and set up as an resources_controller_for :items


Unfortunately, this setup raises an "NoRecognizedRoute" Exception
within the resources_controller.rb, when the locale part is present in
the path ( e.g. for "de" in the example above)

My workaround is, removing the locale part of the path before handing
it over to route recognizing.

def recognized_route
...
# original line
route.recognize(path, environment)

# patched line
route.recognize(path.sub( %r(^/([a-zA-Z]{2})(?=/|$)), ""),
environment)
...
end


That seems kinda smelly for me, so what I really need is the
possiblity to add the :resource_path parameter in the routes mapping,
like we can use it for named routes. Is there any special reason why
this is not possible?

map.resources :items, :resource_path => "/items"


Regards,
Alexander Hoth

--

Web Application Developer
mailto:alexand...@me.com




Ian White

unread,
Feb 13, 2009, 9:28:04 AM2/13/09
to resources_...@googlegroups.com
Hi Alexander,

I've just pushed a change that makes RC much less picky about which
route is used to invoke the controller. I;m still working through it,
so seeing if it works for your case would be very useful knowledge for
me.

Cheers,
Ian

Alexander Hoth

unread,
Feb 13, 2009, 11:04:04 AM2/13/09
to resources_...@googlegroups.com

Hi Ian,

I've just tried the commited changes, but it still raises a
NoRecognizedRoute exception here: route.recognize(path, environment) with
request.path = "/de/items"

Regards,
Alexander

Ian White

unread,
Feb 13, 2009, 11:28:36 AM2/13/09
to resources_...@googlegroups.com
Hi Alexander,

Thanks for the feedback.

Back a few steps: Have you tried setting :resource_path to '/items'
in route definition? (because I would expect that to work)
i.e. Are you saying that

map.resources :items, :requirements => {:resource_path => '/items' }

is not solving your problem?

Cheers,
Ian
Reply all
Reply to author
Forward
0 new messages