Given the code (in routes.rb):
resources :products do
member do
get :delete #this works
delete delete: "products#destroy" #this doesn't work
delete "delete" => "products#destroy" #but this works
end
end
Why the line delete delete: "products#destroy" doesn’t work and the line delete "delete" => "products#destroy" works?
Rails version 3.2.11
The reason why this doesn’t work and if you follow the error backtrace is because of the following line in the
mapper.rbin Rails.This is called by all the methods behind the scenes (e.g
delete,post,get,put). The line that we are specifically looking for is the one that goes like this:Not sure why they are checking against a String but since the name is a symbol and not a
Stringbut aSymbol. That pretty much sends that path as a nil value intodecomposed_matchcausing somewhere down the line the reason why you cannot use a symbol in the routes.NOTE
The reason why
get :deleteworks is because of the line before thematchmethod is called.Specifically under this method
the line
args.extract_options!removes a hash out of the array. You can find this under the fileextract_options.rbwhich is an added method to the classArray.Anyhow, since
get :deleteis not a hash but a single parameter it gets mapped to something like thisNow, the other ones get mapped like this take for example
delete delete: "product#destroy"Then it goes back to my original statement as to why Symbols don’t work in the routes.