Topic: Refactoring Routes... these need to DRY up

map.acoustics '/acoustics', :controller => 'products', :action => 'products', :id => 'acoustics'
  map.electrics '/electrics', :controller => 'products', :action => 'products', :id => 'electrics'
  map.bass '/bass', :controller => 'products', :action => 'products', :id => 'bass'
  map.amps '/amps', :controller => 'products', :action => 'products', :id => 'amps'
  map.effects '/effects-other', :controller => 'products', :action => 'products', :id => 'effects-other'

These are routes for product categories.  Inside the category I am displaying the products that belong_to that category.  Is there any way to clean this up. 

Using Rails 2.3.3

thanks

Re: Refactoring Routes... these need to DRY up

If you're talking strictly about cleaning up the routes as they are, then perhaps you could do the following:

  map.with_options :controller => 'products', :action => 'products' do |product|
    product.acoustics '/acoustics',     :id => 'acoustics'
    product.electrics '/electrics',     :id => 'electrics'
    product.bass      '/bass',          :id => 'bass'
    product.amps      '/amps',          :id => 'amps'
    product.effects   '/effects-other', :id => 'effects-other'
  end

That will produce the following routes:

acoustics  /acoustics      {:controller=>"products", :id=>"acoustics", :action=>"products"}
electrics  /electrics      {:controller=>"products", :id=>"electrics", :action=>"products"}
     bass  /bass           {:controller=>"products", :id=>"bass", :action=>"products"}
     amps  /amps           {:controller=>"products", :id=>"amps", :action=>"products"}
  effects  /effects-other  {:controller=>"products", :id=>"effects-other", :action=>"products"}

If you're okay with it you could also reduce those routes to a single one which is more extensible, but has a category (or whatever decide to call it) prefix:

map.product_category '/category/:id', :controller => 'products', :action => 'products'

It would be use like this:

product_category_path(:acoustics) => "/category/acoustics"

Does that help at all?

I'm a Phoenix Ruby on Rails developer and startup junkie kicking ass at Flatterline, a Ruby on Rails web application development company.