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
?
The :as option creates a named path. You can then call this path in your controllers and views (e.g. redirect_to things_path ). This isn't very useful for the root path (as it already named root ), but is very useful for new routes you add.
In Rails, a RESTful route provides a mapping between HTTP verbs, controller actions, and (implicitly) CRUD operations in a database. A single entry in the routing file, such as. map.resources :photos. creates seven different routes in your application: HTTP verb.
This is the simple option. When you use namespace , it will prefix the URL path for the specified resources, and try to locate the controller under a module named in the same manner as the namespace.
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 :constraints => { :id => /regexp/ }
argument to map.resources
.
See my related question and answer for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With