I am new to Rails and came to know about the destroy action.When we write a destroy action for deleting something, in the link to delete it, we write the code:
method: :delete
So is the method parameter used only for delete, or is it used somewhere else too?
Thanks in advance.
By default (Incase if you don't mention method type) it take HTTP
method type as GET
So explicitly for any other HTTP
request you need to mention HTTP
method type for request.
Destroy action(which is use to delete some record) should be delete
type HTTP
request. so in link it need to mention method: :delete
otherwise it serve request as get
. hopefully this will clear your doubt.
References: -
https://guides.rubyonrails.org/routing.html
https://guides.rubyonrails.org/v2.3/routing.html#restful-routes