我正在研究小型Rails应用程序的销毁功能。目前,当我点击删除我收到以下错误:为什么销毁方法不正确地重定向?
No route matches [POST] "/note/1"
下面是相关控制方法:
def destroy
if Note.find(params[:id]).destroy
redirect_to note_index_path, notice: 'Note deleted!'
else
redirect_to note_path, notice: 'Note failed to updated'
end
end
这里是一个链接例如:
<p><%= link_to 'Delete Note', { action: :destroy, id: @note.id }, method: :destroy, data: { confirm: 'Are you sure?' } %></p>
这里是路线:
Prefix Verb URI Pattern Controller#Action
note_index GET /note(.:format) note#index
POST /note(.:format) note#create
new_note GET /note/new(.:format) note#new
edit_note GET /note/:id/edit(.:format) note#edit
note GET /note/:id(.:format) note#show
PATCH /note/:id(.:format) note#update
PUT /note/:id(.:format) note#update
DELETE /note/:id(.:format) note#destroy
root GET / note#index
准确地说,为什么它说 - 没有该路线的POST请求。 –