2012-03-03 32 views
0

我有簡單的刪除鏈接:爲什麼刪除方法給我錯誤的路徑?與

= link_to "Delete", messages_path(message.id), :method => :delete

給我的錯誤:No route matches [DELETE] "/messages.316"

如何解決這一問題?

我有紅寶石1.9.3p0的Rails 3.1.1

我的routes.rb

resources :messages do 
    collection do 
     get :outbox 
    end 
    end 

當我將其更改爲message_path我收到wrong number of arguments (0 for 1) - > full_trace:https://gist.github.com/1967988
- >所有文件: https://gist.github.com/1967994

outbox_messages GET /messages/outbox(.:format)   {:action=>"outbox", :controller=>"messages"} 
      messages GET /messages(.:format)     {:action=>"index", :controller=>"messages"} 
        POST /messages(.:format)     {:action=>"create", :controller=>"messages"} 
     new_message GET /messages/new(.:format)    {:action=>"new", :controller=>"messages"} 
     edit_message GET /messages/:id/edit(.:format)  {:action=>"edit", :controller=>"messages"} 
      message GET /messages/:id(.:format)    {:action=>"show", :controller=>"messages"} 
        PUT /messages/:id(.:format)    {:action=>"update", :controller=>"messages"} 
        DELETE /messages/:id(.:format)    {:action=>"destroy", :controller=>"messages"} 

編輯:How to destroy polymorphic model? Method destroy missing argument

+0

什麼是您的routes.rb文件有哪些? – 2012-03-03 20:09:10

+0

資源:消息 – tomekfranek 2012-03-03 20:13:50

+0

'rake routes'的輸出是什麼?你的'Message'模型是什麼樣的? – 2012-03-03 20:33:18

回答

4

你需要說message_path(單數),因爲它是一個單一消息路徑:

link_to "Delete", message_path(message.id), :method => :delete 
+0

這是我message_controller:https://gist.github.com/1967994 – tomekfranek 2012-03-03 20:26:39

+0

@regedarek好了...在那裏我的回答有問題?擁有你的控制器代碼是沒有必要的。 – 2012-03-03 20:27:44

+0

是當我使用代碼從您的回答,我收到此錯誤:'''錯誤的參數數目(0 1)'''全部跟蹤:https://gist.github.com/1968069 – tomekfranek 2012-03-03 20:34:37

0

not messages_path。 messages_path返回索引。

1

您使用了錯誤的URL幫手。只需傳遞message變量作爲link_to的第二個參數即可。

例子:

= link_to "Delete", message, :method => :delete 
+0

最好的答案;) – lucapette 2012-03-03 20:27:34

+0

我得到這個:'''undefined method' acts_as_messageable_message_path'for#<#:0x000000036cc520>'''full tr​​ace:https://gist.github。 COM/1967994#file_error +全+跟蹤 – tomekfranek 2012-03-03 20:29:20

相關問題