2011-04-02 50 views
0

我在使用複選框刪除多個konkurrancers時遇到問題。 我提交我的表單時出現此錯誤鑑於:Rails有助於刪除多個

Routing Error 

No route matches "/admin/konkurrancers/delete_multiple" 

我index.erb.html:

<h1>Alle konkurrencer</h1> 
<div id="konkurrancer"><%= render 'konkurrencer', :remote => true %></div> 
<%= link_to 'Opret konkurrence', new_admin_konkurrancer_path, :class => 'link' %> 
<%= link_to 'Tilbage', :admin, :class => 'admina' %> 

我_konkurrencer部分:

<% form_tag delete_multiple_admin_konkurrancers_path do %> 
<div id="tabel"> 
<table id="tabel1" border="0" bordercolor="#000000" style="background-color:#FFFFFF" width="950" cellpadding="0" cellspacing="0"> 
    <tr id="toptr"> 
    <td>&nbsp;</td> 
     <td ><%= sortable "name", "Navn" %></td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
<% for konkurrancer in @konkurrancers %> 
    <tr class="thumbnail-item" onmouseout="this.style.background='white';" onmouseover="this.style.background='#99ff33';this.style.cursor='pointer'"> 
    <td><%= check_box_tag "konkurrancer_ids[]", konkurrancer.id %></td> 
    <td>&nbsp;</td> 
    <td><%= link_to 'Vis', admin_konkurrancer_path(konkurrancer.id) %></td> 
    <td><%= link_to 'Redigere', {:action => 'edit', :id => konkurrancer.id}, :class => 'action edit' %></td> 
    <td><%= link_to 'Slet', admin_konkurrancer_path(konkurrancer.id), :confirm => 'Are you sure?', :method => :delete %></td> 
    </tr> 
<% end %> 
</table> 
<div id="pagenavi"> 
<%= submit_tag "Delete Checked" %> 
<% end %> 
<%= hidden_field_tag :direction, params[:direction] %> 
<%= hidden_field_tag :sort, params[:sort] %> 
</div> 

我的管理員/ konkurrancers控制器:

def delete_multiple 
    @konkurrancer = Konkurrancer.find(params[:konkurrancer_ids]) 
    @konkurrancer.each do |konkurrancer| 
    konkurrancer.destroy 
    end 
end 

我的路線:

delete_multiple_admin_konkurrancers DELETE /admin/konkurrancers/delete_multiple(
.:format) {:action=>"delete_multiple", :controller=>"admin/konkurrancers"} 
       admin_konkurrancers GET /admin/konkurrancers(.:format) 
      {:action=>"index", :controller=>"admin/konkurrancers"} 
            POST /admin/konkurrancers(.:format) 
      {:action=>"create", :controller=>"admin/konkurrancers"} 
      new_admin_konkurrancer GET /admin/konkurrancers/new(.:format) 
      {:action=>"new", :controller=>"admin/konkurrancers"} 
      edit_admin_konkurrancer GET /admin/konkurrancers/:id/edit(.:forma 
t)  {:action=>"edit", :controller=>"admin/konkurrancers"} 
       admin_konkurrancer GET /admin/konkurrancers/:id(.:format) 
      {:action=>"show", :controller=>"admin/konkurrancers"} 
            PUT /admin/konkurrancers/:id(.:format) 
      {:action=>"update", :controller=>"admin/konkurrancers"} 
            DELETE /admin/konkurrancers/:id(.:format) 
      {:action=>"destroy", :controller=>"admin/konkurrancers"} 

我的routes.rb

命名空間:管理員做 資源:konkurrancers做 集合所做 刪除:delete_multiple 結束 結束 結束

回答

1

的錯誤是因爲您正在尋找的路徑在您的路線文件中沒有正確定義。

我不認爲在rails3中支持該語法,您似乎在使用rails3和rails2.x的混合。從應用程序的根目錄運行rake routes,它會顯示您擁有的所有路線。使用你的語法,我沒有提到delete_multiple路徑。這應該工作:

namespace :admin do 
    resources :konkurrancers do 
     collection do 
     delete :delete_multiple 
     end 
    end 
    end 

現在,由於您使用的是標準的form_tag,我相信默認方法是POST,你想改變這個,則刪除該路由工作正常。你的表單標籤更改爲:

form_tag delete_multiple_admin_konkurrancers_path, :method => :delete 
+0

現在我得到提交此錯誤:路由錯誤 沒有路由匹配「/管理/ konkurrancers/delete_multiple」 – 2011-04-02 12:27:38

+0

對不起,那是因爲你可能POST'ng它,這是默認的。 – brad 2011-04-02 12:40:29

+0

如何將其更改爲刪除? – 2011-04-02 12:42:02