Rails路由:我错过了什么?

时间:2011-02-22 16:48:56

标签: ruby-on-rails routing

我的应用有门票,门票可以“解决”。我可以通过AJAX发布到:解决操作没有问题,但我无法通过普通的HTML表单进行POST。我得到No route matches "/tickets/321/resolve"。 HTML表单和JS都指向相同的URL。我做错了什么?

路线:

resources :tickets do
  post :resolve, :on => :member
end

控制器:

def resolve
  resource.resolved!

  respond_to do |wants|
    wants.html { redirect_to :back }
    wants.js
  end
end

形式:

= form_for(ticket, :url => resolve_ticket_path(ticket)) do |f|
  ...

1 个答案:

答案 0 :(得分:1)

实际上,当您尝试发送包含现有资源(票证)的表单时,默认情况下会发送PUT请求,因此您应该设置:method => :post清除或更改路由

post :resolve, :on => :member

put :resolve, :on => :member