为什么删除方法给我错误的路径?和 [英] Why delete method gives me wrong path? with
本文介绍了为什么删除方法给我错误的路径?和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的删除链接:
I have simple delete link:
= link_to "Delete", messages_path(message.id), :method => :delete
给我错误:No route matches [DELETE] "/messages.316"
该如何解决?
我有ruby 1.9.3p0 Rails 3.1.1
I have ruby 1.9.3p0 Rails 3.1.1
我的路线.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
when i change this to message_path
i recieve wrong number of arguments (0 for 1)
-> full_trace: https://gist.github.com/1967988
-> all files: 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"}
推荐答案
您需要说message_path
(单数),因为它是单消息的路径:
You need to say message_path
(singular) since it is the path for a single message:
link_to "Delete", message_path(message.id), :method => :delete
这篇关于为什么删除方法给我错误的路径?和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文