Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using link_to with delete action in rails

In my grid this,

link_to('Edit', edit_manage_user_path(user.id))

works fine but this,

link_to('Delete', delete_manage_user_path(user.id))

gives the error "undefined method `delete_manage_user_path' for #<#:0xc05439c>" given that there is a delete action in my controller..

Any idea why this error is coming?

like image 920
Anss Avatar asked Dec 19 '22 11:12

Anss


2 Answers

If you use resources routes, path to destroy action is the same as to show, but you should use HTTP DELETE method:

link_to 'Delete', [:manage, user], method: :delete
like image 194
Marek Lipka Avatar answered Jan 03 '23 09:01

Marek Lipka


 link_to 'Delete', manage_user_path(user), method: :delete

This will call your delete action. there is no such path delete_manage_user_path(user) if you are using restful routing.

like image 28
Dipak Gupta Avatar answered Jan 03 '23 08:01

Dipak Gupta