views:

29

answers:

1

Consider a PersonController which has a list action. A user can choose to list all people, or only males or females; currently, to do that, they'd have to go to /people/m or /people/f, corresponding to the route

map.list_people "people/:type",
  :conditions => { :method => :get },
  :requirements => { :type => /a|m|f/ },
  :defaults => { :type => 'a' }

(/people/a works the same as just /people/, and lists all people).

I want to change my routing so that I could have two routes, /males/ and /females/ (instead of people/:type), both of which would go to PersonController#list (DRY -- aside from an extra parameter to what's being searched, everything else is identical), but will inherently set the type -- is there a way to do this?

+3  A: 
map.with_options(:controller => "people", :action => "index") do |people|
  people.males 'males', :type => "m"
  people.females 'females', :type => "f"
end

Then you should be able to do males_path or males_url to get the path for this, and I'm sure you can guess what you do to get the path to females.

Ryan Bigg
Perfect, that's exactly what I was looking for, but couldn't find it in the routing guide. Thanks!
Daniel Vandersluis