Reputation: 1395
The destroy action is working for me in one part of my app, but I can't get it to work in a different view that is using a separate controller.
I am getting the error: No route matches {:action=>"destroy", :controller=>"letsgo"}
View:
<% for letsgo in @letsgos %>
<li>
<b>Let's Go...<span class="content"><%= letsgo.content %></span></b>
<%= link_to 'Delete', { :controller => 'letsgo', :action => 'destroy'},
{ :confirm => 'Are you sure?', :method => :delete, :remote => true} %>
<% end %>
Routes:
resources :letsgos, only: [:create, :destroy]
LetsGos controller:
def destroy
@letsgo.destroy
redirect_to root_url
end
This code works if I am under the letsgos
view: <%= link_to "delete", letsgo, method: :delete, data: { confirm: "You sure?" }%>
Destroy action works if I am working under the letsgos
view, but I am working under a different folder it no longer works. What I am doing is listing all the content
from the letsgos
table, and providing a destroy action for each content.
Routes:
letsgos_eatdrink GET /letsgos/eatdrink(.:format) letsgos#eatdrink
letsgos_listenwatch GET /letsgos/listenwatch(.:format) letsgos#listenwatch
letsgos_play GET /letsgos/play(.:format) letsgos#play
letsgos_other GET /letsgos/other(.:format) letsgos#other
letsgos_explore GET /letsgos/explore(.:format) letsgos#explore
repost_letsgo POST /letsgos/:id/repost(.:format) letsgos#repost
interested_letsgo POST /letsgos/:id/interested(.:format) letsgos#interested
GET /letsgos(.:format) letsgos#index
POST /letsgos(.:format) letsgos#create
new_letsgo GET /letsgos/new(.:format) letsgos#new
edit_letsgo GET /letsgos/:id/edit(.:format) letsgos#edit
GET /letsgos/:id(.:format) letsgos#show
PATCH /letsgos/:id(.:format) letsgos#update
PUT /letsgos/:id(.:format) letsgos#update
DELETE /letsgos/:id(.:format) letsgos#destroy
Upvotes: 0
Views: 2753
Reputation: 21
THIS WORKS FOR me too! Just add DATA:
before { :confirm..... }
...and the Confirm Delete Dialog works.
<%= link_to 'Delete', { :controller => 'letsgos', :action => 'destroy', :id => letsgo.id },
data: { :confirm => 'Are you sure?', :method => :delete, :remote => true} %>
Upvotes: 0
Reputation: 947
You are not passing the ID of the letsgo
to the route:
<%= link_to 'Delete', { :controller => 'letsgos', :action => 'destroy', :id => letsgo.id },
{ :confirm => 'Are you sure?', :method => :delete, :remote => true} %>
As written in your paths:
letsgo DELETE /letsgos/:id(.:format) letsgos#destroy
It's not tested, but should be like this
Upvotes: 2