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