gregm
April 26, 2010, 9:21pm
1
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
gregm
May 4, 2010, 1:08am
2
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