我知道这个问题被问了很多次,但到目前为止,没有一个食谱对我有帮助。
我有一个用 Ruby 2.0.0、Rails 4.0.0 编写的应用程序,带有以下 routes.rb:
resources :announcements do
end
生成以下路线:
announcements GET /announcements(.:format) announcements#index
POST /announcements(.:format) announcements#create
new_announcement GET /announcements/new(.:format) announcements#new
edit_announcement GET /announcements/:id/edit(.:format) announcements#edit
announcement GET /announcements/:id(.:format) announcements#show
PATCH /announcements/:id(.:format) announcements#update
PUT /announcements/:id(.:format) announcements#update
DELETE /announcements/:id(.:format) announcements#destroy
然后在 HTML 中我使用非常简单的构造:
<%= button_to 'X', announcement, method: :delete %>
这会产生以下代码:
<form method="post" class="button_to" action="/announcements/525c0d28b9fd0171e2000003">
<div>
<input type="hidden" value="delete" name="_method">
<input type="submit" value="X">
<input type="hidden" value="DR+QjuAG9npqqWRV16Zq0G4Cq3lGpNHY0qjV8LJpUZo=" name="authenticity_token">
</div>
</form>
一切看起来都非常简单、干净和正确。不过,我收到“无路线匹配”错误。为什么?