Rails routing: What am I missing?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 05:24:07

问题


My app has Tickets, and a ticket can be "resolved". I can POST via AJAX to the :resolve action with no issues, but I cannot POST via a normal HTML form. I get No route matches "/tickets/321/resolve". Both the HTML form and the JS point to the same exact URL. What am I doing wrong?

Routes:

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

Controller:

def resolve
  resource.resolved!

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

Form:

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

回答1:


Actually when you are trying to send your form with exists resource (ticket) rails by default will send PUT request, so you should set :method => :post clear or change route from

post :resolve, :on => :member

to

put :resolve, :on => :member


来源:https://stackoverflow.com/questions/5081153/rails-routing-what-am-i-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!