Forum: Ruby on Rails Odd Routing - How To?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7fef3e875e6d8d8e1802f401f09bb0f5?d=identicon&s=25 Chris Parrish (Guest)
on 2006-01-03 06:52
I am working on an app with a requirement that has yielded an unexpected
problem for Rails routing.

We have several controllers that handle regional data (one controller
per data type - weather, demographics, etc).  The problem is that there
is one region who's actions and output are different.

We intend to create two controllers for each data type (i.e.
weather_controller to handle requests for all regions but the one and
regionx_weather_controller with its own special methods, data, and
templates).

So, with that in mind, the requirement is to have the url of the form:

:region/:controller/:action

That's great for the main regions but this bastard region needs a
routing statement like:

 map.connect 'regionx/:special/:action', :controller => 'regionx_' +
:special

(which, of course, doesn't work - or I wouldn't be asking this)

Apparently :special gets packaged up as a param and sent to the
controller (if I name a valid one) but I can't access the symbol here
for some reason.
D8cb8c8cd40ddf0cd05241443a591868?d=identicon&s=25 Duane Johnson (Guest)
on 2006-01-03 14:58
(Received via mailing list)
On Jan 2, 2006, at 10:52 PM, Chris Parrish wrote:

> weather_controller to handle requests for all regions but the one and
>  map.connect 'regionx/:special/:action', :controller => 'regionx_' +
> :special
>
> (which, of course, doesn't work - or I wouldn't be asking this)
>
> Apparently :special gets packaged up as a param and sent to the
> controller (if I name a valid one) but I can't access the symbol here
> for some reason.
>

Yeah, that's not going to work.  Unfortunately there are only two
options (that I know of--if someone else has something, please chime
in).

Option 1:

map.connect 'regionx/weather/:action', :controller => 'regionx_weather'
map.connect 'regionx/demographics/:action', :controller =>
'regionx_demographics'
map.connect 'regionx/etc/:action', :controller => 'regionx_etc'

Option 2:

map.connect 'regionx/:special/:action', :controller =>
'regionx_dispatcher'

class RegionxDispatcherController < ApplicationController
   def index
     render_component :controller => 'regionx_' + params[:special].to_s
   end
end

Duane Johnson
(canadaduane)
http://blog.inquirylabs.com/
Bb46488d2c90d51f366cafc776e2b3ad?d=identicon&s=25 Jeff Lindsay (progrium)
on 2006-02-21 12:37
I'm looking to accomplish something similar to this myself, only my
situation is a little different. Ideally, I'd like to have a whole new
type of controller so I can have controllers with the same name in
different "namespaces".

In other words, I can have a foo_controller and a foo_xcontroller, where
the latter is used if x is in the url. I've been trying to hack Routes
to handle something like this, but I was hoping I could find some help
and ideas here.
This topic is locked and can not be replied to.