没有路由匹配销毁行动
销毁行为在我的应用程序的一部分中为我工作,但我无法在另一个使用单独控制器的视图中使其工作。没有路由匹配销毁行动
我收到错误:No route matches {:action=>"destroy", :controller=>"letsgo"}
查看:
<% 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 %>
路线:
resources :letsgos, only: [:create, :destroy]
LetsGos控制器:
def destroy
@letsgo.destroy
redirect_to root_url
end
此代码的工作,如果我下在letsgos
观点:<%= link_to "delete", letsgo, method: :delete, data: { confirm: "You sure?" }%>
销毁行动工作,如果我的letsgos
视图下工作,但我在不同的文件夹就不再起作用工作。我正在做的是从letsgos
表中列出所有content
,并为每个内容提供销毁操作。
路线:
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} %>
写在你的路:
letsgo DELETE /letsgos/:id(.:format) letsgos#destroy
这不是测试,但应该是这样的
我在发布之前实现了'letsgo.id',它给了我一个路由错误,所以我删除了它。为了给它添加确切的错误,没有路由匹配{:action =>“destroy”,:controller =>“letsgo”,:id => 9}'。 – pwz2000 2014-10-20 21:40:54
所以''':controller =>'letsgos'''也有错误,请参阅http://guides.rubyonrails.org/routing.html#static-segments – 2014-10-20 21:43:47
这也适用于我!只需在{ :confirm..... }
之前添加DATA:
...并确认删除对话框起作用。
<%= link_to 'Delete', { :controller => 'letsgos', :action => 'destroy', :id => letsgo.id },
data: { :confirm => 'Are you sure?', :method => :delete, :remote => true} %>
命令的结果是什么:'''rake routes'''? – 2014-10-20 21:18:48
@TomHert添加路线 – pwz2000 2014-10-20 21:20:41
您是否需要在您的'link_to'删除行中传入要删除的'@ letsgo'对象的':id'? – Alireza 2014-10-20 21:25:06