views:

92

answers:

1

I have a resource exposed with two actions ONLY ('name' and 'number') and I would like to have a RESTful interface like:

resource/name/1

resource/number/ABC

but with the default

map.resources :controller_name

this doesn't work. How can I add these 2 custom actions? (total n00b here)

Thanks for any feedback!

+3  A: 

You can't do this with a resource. You need to map a custom (named) route.

map.connect 'resource/:id/name', :controller => 'resources', :action => 'name'
map.connect 'resource/:id/number', :controller => 'resources', :action => 'number'

# the same but with named routes

map.name_resource 'resource/:id/name', :controller => 'resources', :action => 'name'
map.number_resource 'resource/:id/number', :controller => 'resources', :action => 'number'
Simone Carletti
second this, you could be even smarter and work out the type of route that you want using a regular expression based on whether the param contained digits only or letters only. http://api.rubyonrails.org/classes/ActionController/Routing.htm
Omar Qureshi