Ruby on rails 销毁操作没有路由匹配
销毁操作在我的应用程序的一部分中对我有效,但我无法让它在使用单独控制器的不同视图中工作 我收到错误:Ruby on rails 销毁操作没有路由匹配,ruby-on-rails,Ruby On Rails,销毁操作在我的应用程序的一部分中对我有效,但我无法让它在使用单独控制器的不同视图中工作 我收到错误:没有路由匹配{:action=>“destroy”,:controller=>“letsgo”} 视图: LetsGos控制器: def destroy @letsgo.destroy redirect_to root_url end 如果我在letsgos视图下: 如果我在letsgos视图下工作,则销毁操作有效,但我在另一个文件夹下工作,它不再有效。我所做的是列出le
没有路由匹配{:action=>“destroy”,:controller=>“letsgo”}
视图:
LetsGos控制器:
def destroy
@letsgo.destroy
redirect_to root_url
end
如果我在letsgos
视图下:
如果我在letsgos
视图下工作,则销毁操作有效,但我在另一个文件夹下工作,它不再有效。我所做的是列出letsgos
表中的所有内容,并为每个内容提供销毁操作
路线:
resources :letsgos, only: [:create, :destroy]
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
您没有将letsgo
的ID传递给路线:
<%= link_to 'Delete', { :controller => 'letsgos', :action => 'destroy', :id => letsgo.id },
{ :confirm => 'Are you sure?', :method => :delete, :remote => true} %>
它没有经过测试,但应该是这样的这对我也适用!只需在{:confirm….}
之前添加数据:
,确认删除对话框就会工作
<%= link_to 'Delete', { :controller => 'letsgos', :action => 'destroy', :id => letsgo.id },
data: { :confirm => 'Are you sure?', :method => :delete, :remote => true} %>
'letsgo',:action=>'destroy',:id=>letsgo.id},
数据:{:确认=>'确定吗?',:方法=>:删除,:远程=>true}%>
命令的结果是什么:rake routes
?@TomHert routes addedDon您不需要在@letsgo
对象的:id
中传递您要在链接到删除行中删除的letsgo.id
?我在这里发布之前实现了letsgo.id
,它给了我一个路由错误,所以我删除了它。为了给出添加的确切错误,没有路由匹配{:action=>“destroy”,:controller=>“letsgo”,:id=>9}
。因此:controller=>“letsgos”中也有错误,请参阅
letsgo DELETE /letsgos/:id(.:format) letsgos#destroy
<%= link_to 'Delete', { :controller => 'letsgos', :action => 'destroy', :id => letsgo.id },
data: { :confirm => 'Are you sure?', :method => :delete, :remote => true} %>