我在views/questions/show.html.erb 中有一个链接,可以让用户删除标签。
<%=link_to "x",
:remote => true,
:url => remove_question_tag_path(@question, tag),
:method => :delete,
:html => { :id => "delete-#{tag.name.parameterize}"} %>
<% end %>
remove_question_tag_path 路由是通过将标签资源嵌套在问题资源中来创建的。
resources :questions do
resources :answers do
member { post :vote }
end
resources :tags do
member do
delete :remove
end
end
end
Rake routes 显示该路由存在,因为我尝试在 url 中使用它
remove_question_tag DELETE /questions/:question_id/tags/:id/remove(.:format) tags#remove
但是,当我单击链接时,它会向 Questions 控制器的 show 操作发出 get 请求,而不是 Tags 控制器的 remove 操作,因为 rake routes 指示是路由的目的地。
Started GET "/questions/25?html%5Bid%5D=delete-outdoors&method=delete&url=%2Fquestions%2F25%2Ftags%2F2%2Fremove" for 127.0.0.1 at 2013-03-26 19:01:00 -0700
你能解释一下我可能做错了什么吗?