2010-10-27 49 views
1

的破壞作用:軌道3銷燬行動失敗

def destroy 
    @tag = Tag.find(params[:id]) 
    @tag.destroy 

    respond_to do |format| 
    format.html { redirect_to(tags_url) } 
    format.xml { head :ok } 
    end 
end 

鏈接:

<a href="/tags/14" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a> 

點擊它呈現的表演動作。

Started GET "/tags/14" for 127.0.0.1 at Wed Oct 27 18:36:41 -0500 2010 
Processing by TagsController#show as HTML 
Parameters: {"id"=>"14"} 
Tag Load (0.2ms) SELECT "tags".* FROM "tags" WHERE ("tags"."id" = 14) LIMIT 1 
Rendered tags/show.html.erb within layouts/application (8.5ms) 
Completed 200 OK in 25ms (Views: 12.1ms | ActiveRecord: 0.2ms) 

javascript_include_tag:默認值包含在我的頁面上,並且腳本標記呈現正確。 Firebug不會給我任何錯誤。這發生在Firefox和Opera中。

回答

1

這可能是你如何寫你的link_to方法。

<%= link_to "Destroy", tag, :method => :delete, :confirm => "Really?" %> 

試試看。


確保你在你的routes.rb文件中聲明的資源,因爲這是什麼讓這個奉送的URL。

在2.3.8它是

map.resources :tags 

在R3我真的不知道,但導遊有它這樣的

resources :tags 
+0

如果你使用內置的傭工 – MatthewFord 2010-10-28 00:10:11

+0

它也可以。唯一的區別是:確認和:方法params的順序是相反的。我將它們切換以防萬一,但事實並非如此。 – herpderp 2010-10-28 00:17:09

+0

你是否在你的路線文件中聲明瞭這個。如果您有map.resources:資源聲明,則此路線僅可用。至少這是2.3.8如何做的,我還沒有升級。 – s84 2010-10-28 00:36:56

0

要使用方法重寫你需要發送_method參數。對於像破壞這樣的操作,它應該是一個表單,您可以使用_method參數設置爲delete進行POST,如果您喜歡,可以在單擊鏈接時用JS構造表單。