开发者

Rails routing: What am I missing?

开发者 https://www.devze.com 2023-02-12 22:00 出处:网络
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

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(ticke开发者_开发百科t)) do |f|
  ...


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
0

精彩评论

暂无评论...
验证码 换一张
取 消