views:

1089

answers:

1

Hello all,

in my current rails application I have a bunch of named routes defined to deal with the static content like this:

map.with_options :controller => 'static_content' do |static|
  static.imprint    'imprint',    :action => 'imprint'
  static.menu1      'menu1',      :action => 'menu1'
  static.menu1_sub1 'menu1/sub1', :action => 'menu1_sub1'
  static.menu1_sub2 'menu1/sub2', :action => 'menu1_sub2'
  static.menu2      'menu2',      :action => 'menu2'
  ...
end

Now I'd like to refactor this quite disgusting piece of routing to have something like this:

map.connect 'menu1/:action', :controller => 'static/menu1'
map.connect 'menu2/:action', :controller => 'static/menu2'
...

I created the controller namespace static and map the actions of all those controllers in the namespace. But now - of course - all those helpful route helpers like *menu1_sub2_path* stop working and I'll have to change them.

Uff! Refactor all usages of path helpers to ugly :controller-:action-style?

So my question is if anybody sees a good way to surround this. Is there a way to define those path helpers - or the way they are created? Or even a smarter way to do those nasty mappings?

Thanks for your help,

Joe

+1  A: 
map.with_options :controller => 'static_content' do |static|
  static.page ':action'
end

then call it:

page_path(:imprint)
Ryan Bigg