我在订单查看页面上,我想更新该订单上的订单项:
我的路线是:
resources :order_line_details do
member do
put :update_barcode
end
end
然后我的form_for:
<%= form_for update_barcode_order_line_detail_path(@order_line_detail) do |f| %>
<%= f.text_field :hds_barcode %>
<%= f.submit 'Submit' %>
<% end %>
当我提交时,它只是再次进入订单:
No route matches "/orders/20888"
Rake路线:(对于订单和orderlinedetails)
orders GET /orders(.:format) {:action=>"index", :controller=>"orders"}
orders POST /orders(.:format) {:action=>"create", :controller=>"orders"}
new_order GET /orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_order GET /orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
order GET /orders/:id(.:format) {:action=>"show", :controller=>"orders"}
order PUT /orders/:id(.:format) {:action=>"update", :controller=>"orders"}
order DELETE /orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
update_barcode_order_line_detail PUT /order_line_details/:id/update_barcode(.:format) {:action=>"update_barcode", :controller=>"order_line_details"}
order_line_details GET /order_line_details(.:format) {:action=>"index", :controller=>"order_line_details"}
order_line_details POST /order_line_details(.:format) {:action=>"create", :controller=>"order_line_details"}
new_order_line_detail GET /order_line_details/new(.:format) {:action=>"new", :controller=>"order_line_details"}
edit_order_line_detail GET /order_line_details/:id/edit(.:format) {:action=>"edit", :controller=>"order_line_details"}
order_line_detail GET /order_line_details/:id(.:format) {:action=>"show", :controller=>"order_line_details"}
order_line_detail PUT /order_line_details/:id(.:format) {:action=>"update", :controller=>"order_line_details"}
order_line_detail DELETE /order_line_details/:id(.:format) {:action=>"destroy", :controller=>"order_line_details"}
我做错了什么?
答案 0 :(得分:7)
form_for
方法的第一个参数应该是表单所针对的对象。然后,您可以使用:url参数手动更改默认URL。尝试这样做:
<%= form_for @order_line_detail, :url => update_barcode_order_line_detail_path(@order_line_detail) do |f| %>
<%= f.text_field :hds_barcode %>
<%= f.submit 'Submit' %>
<% end %>