On Jan 2, 2006, at 10:52 PM, Chris Parrish wrote:
> 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.
>
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/