bhanu bhanu - 3 months ago 24x
Ruby Question

How do I specify destroy path helper in a view of my Rails app?

I have a model Category in my Rails app. According to rails RESTful Routes, I can perform CRUD Operations on model, having

resources: categories
defined in my routes.rb.

But how do i define destroy path helper in my view to perform
action, just like
to edit the record. I tried like this
but getting error as

undefined method `destroy_category_path' for #<#<Class:0x00000005371298>:0x000000053734f8>


The path is exactely the same as for show action, the only idfference is that you need to use DELETE verb:

button_to @category, method: :delete

Note, it is not considered safe to use links having destructive/constructive actions, as those might be visited by robots.