Frage

I'm currently updating a Rails 3.2 application to Rails 4 and ran into an issue with Rails now using PATCH as the primary HTTP verb for updates. I have a form that users can use to create an order. This form uses the model "temporders". Once the user sends the form, he will be redirected to /orders/new where he can review and confirm the first form. Orders#new uses "@order = Temporder.find session[:temporder]" to get the data for the confirmation form. That form should be sent as a POST request to "/orders". "Orders" is declared as a restful resource.

orders_path          GET     /orders(.:format)           orders#index
                     POST    /orders(.:format)           orders#create
new_order_path       GET     /orders/new(.:format)       orders#new
edit_order_path      GET     /orders/:id/edit(.:format)  orders#edit
order_path           GET     /orders/:id(.:format)       orders#show
                     PATCH   /orders/:id(.:format)       orders#update
                     PUT     /orders/:id(.:format)       orders#update
                     DELETE  /orders/:id(.:format)       orders#destroy

<%= form_for @order, :as => :order, :url => orders_path, :html => {:multipart => true} do |f| -%>

However, when I send the form Rails generates the error 'No route matches [PATCH] "/orders"' I tried adding "method: :post" but it didn't help. I suspect that Rails 4 assumes that this is an update form for an existing order object since I get the data from an existing "temporder" object and therefore uses PATCH instead of POST. Question is: How can I force the POST method for this form?

War es hilfreich?

Lösung

I found the problem. I was looking up the syntax for setting the HTTP method in a wrong/outdated manual. It should be <%= form_for @order, :as => :order, :url => orders_path, :html => {:multipart => true, :method => :post} do |f| -%>

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top