views:

50

answers:

2

I have the following route defined:

map.resources :images, :only => [ :index, :new, :destroy ]

when I do a rake routes I get the following:

image DELETE /images/:id(.:format) {:action=>"destroy", :controller=>"images"}

My problem is, I would like to use file names as my :id including any extension. At the moment my ids are getting to the controller minus the extension. Is there any way I can customize the above map.resources to generate the following path:

image DELETE /images/:id {:action=>"destroy", :controller=>"images"}

i.e. not have the extension used as :format?

A: 

I couldn't figure out how to pass the id intact to the controller but this is the work around I used to reconstruct the id:

id = [ params['id'], params['format'] ].compact.join '.'
tpower
This presumes your filenames follow a very strict filename.ext format, but once you expose this to users they're probably going to contain spaces, multiple dots, and who knows what else that will almost totally hose your ability to put them in a URL without escaping.
tadman
Correct, I should add some URL encoding.
tpower
+1  A: 

The . character is defined in ActionController::Routing::SEPARATORS, which lists special characters to split the URL on.

If you want to avoid splitting the URL at .s, you need to pass a :requirements => { :id => /regexp/ } argument to map.resources.

See my related question and answer for more info.

nfm
Thanks, adding the regex did the trick.
tpower