# Link\_to delete action

**URL:** <https://www.ruby-forum.com/t/link-to-delete-action/187614>\
**Category:** Rails\
**Created:** [April 26, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/link-to-delete-action/187614 "2010-04-26T21:21:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [April 26, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/link-to-delete-action/187614/1 "2010-04-26T21:21:32Z")

</div>

Hi,  
I am trying to generate a link to delete a relationship, so I’ve done  
the code bellow. THis is the full code, the part for deleting the  
relationship is at the bottom of the code. I am using a restful  
controller

\<% unless item.user\_participe?(current\_user) %\>  
\<%form\_for Participant.new do |f| %\>  
\<%= f.hidden\_field :defi\_id, :value =\> item.id%\>  
\<%= f.submit “Participer!”, :disabled =\> !current\_user %\> \<%=  
link\_to(“CrÃ©ez un compte pour participer”, register\_path) unless  
current\_user %\>  
\<% end %\>

\<%else%\>  
_Vous participez Ã ce dÃ©fi_  
\<%= link\_to “Ne plus participer”,  
participant\_path(item.participants.find\_by\_user\_id(current\_user.id)) ,  
:method =\> :delete, :confirm =\> “Etes vous sur de ne plus vouloir  
participer?” %\>  
\<%end%\>

This is the error message:  
participant\_url failed to generate from {:action=\>“show”,  
:controller=\>“participants”, :id=\>#\<Participant user\_id: 1, defi\_id: 1,  
is\_valide: “false”, fin\_defi: “2010-04-24 00:00:00”, created\_at:  
“2010-04-25 15:15:35”, updated\_at: “2010-04-25 15:15:35”\>}, expected:  
{:action=\>“show”, :controller=\>“participants”}, diff:  
{:id=\>#\<Participant user\_id: 1, defi\_id: 1, is\_valide: “false”,  
fin\_defi: “2010-04-24 00:00:00”, created\_at: “2010-04-25 15:15:35”,  
updated\_at: “2010-04-25 15:15:35”\>}

Greg

---

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [May 4, 2010, 1:08am UTC](https://www.ruby-forum.com/t/link-to-delete-action/187614/2 "2010-05-04T01:08:21Z")

</div>

The reason it is failing is because it is performing a GET request.

Wrap the “delete relationship” in a form( with :method =\> :delete) and  
it should work

–  
Punit

Greg Ma wrote:

> Hi,  
> I am trying to generate a link to delete a relationship, so I’ve done  
> the code bellow. THis is the full code, the part for deleting the  
> relationship is at the bottom of the code. I am using a restful  
> controller
> 
> \<% unless item.user\_participe?(current\_user) %\>  
> \<%form\_for Participant.new do |f| %\>  
> \<%= f.hidden\_field :defi\_id, :value =\> item.id%\>  
> \<%= f.submit “Participer!”, :disabled =\> !current\_user %\> \<%=  
> link\_to(“CrÃ©ez un compte pour participer”, register\_path) unless  
> current\_user %\>  
> \<% end %\>
> 
> \<%else%\>  
> _Vous participez Ã ce dÃ©fi_  
> \<%= link\_to “Ne plus participer”,  
> participant\_path(item.participants.find\_by\_user\_id(current\_user.id)) ,  
> :method =\> :delete, :confirm =\> “Etes vous sur de ne plus vouloir  
> participer?” %\>  
> \<%end%\>
> 
> This is the error message:  
> participant\_url failed to generate from {:action=\>“show”,  
> :controller=\>“participants”, :id=\>#\<Participant user\_id: 1, defi\_id: 1,  
> is\_valide: “false”, fin\_defi: “2010-04-24 00:00:00”, created\_at:  
> “2010-04-25 15:15:35”, updated\_at: “2010-04-25 15:15:35”\>}, expected:  
> {:action=\>“show”, :controller=\>“participants”}, diff:  
> {:id=\>#\<Participant user\_id: 1, defi\_id: 1, is\_valide: “false”,  
> fin\_defi: “2010-04-24 00:00:00”, created\_at: “2010-04-25 15:15:35”,  
> updated\_at: “2010-04-25 15:15:35”\>}
> 
> Greg
