Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 DELETE action, just like edit_category_path(@category) to edit the record. I tried like this destroy_category_path(@category) but getting error as

undefined method `destroy_category_path' for #<#<Class:0x00000005371298>:0x000000053734f8>
like image 302
bhanu Avatar asked Mar 19 '23 09:03

bhanu


1 Answers

The path is exactly the same as the show action ('/categories/:id'), but you also need to specify the DELETE HTTP method:

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.

like image 178
BroiSatse Avatar answered Apr 26 '23 07:04

BroiSatse