銷燬行爲在我的應用程序的一部分中爲我工作,但我無法在另一個使用單獨控制器的視圖中使其工作。沒有路由匹配銷燬行動
我收到錯誤: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
命令的結果是什麼:'''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