我是ROR的新开发人员,我有问题询问添加到购物车。我想灵活更新数量添加到购物车。我有如下所示的代码
在我的观看/ cart / show.html.erb
中显示<% total = 0 %>
<table>
<td>Name</td>
<td>Price</td>
<td>Quantity</td>
<td>Amount</td>
<td>update</td>
<% for item in @cart.line_items %>
<tr>
<td><%= item.product.name %></td>
<td><%= item.product.price %></td>
<td><%= item.qty %></td>
<td><%= item.product.price.to_f * item.qty.to_f %></td>
<td>
<%= form_for 'item', :url => {:controller => 'line_items', :action => 'update', id: item} do |f| %>
<div class="field">
<%= f.number_field :qty, :value => item.qty %>
<%= submit_tag "Update" %>
</div>
<% end %>
</td>
</tr>
<td><% total += item.product.price.to_f * item.qty.to_f %></td>
<% end %>
<tr>
<td></td>
<td></td>
<td></td>
<td><%= total %></td>
</tr>
<tr>
<td><%= link_to "Shopping Continue", products_path %></td>
<td></td>
<td></td>
<td></td>
<td><%= link_to 'Empty Cart', cart_path(@cart), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
</table>
当我点击提交按钮更新时,它显示错误,如此
路由错误
没有路线匹配[POST]&#34; / line_items / 195 / edit&#34;
Rails.root:C:/ railsapp / shoppingcat_01
应用程序跟踪|框架跟踪|完整追踪 路由
路线优先从上到下匹配
请帮帮我
答案 0 :(得分:1)
您可以通过
写出您的路线rake routes
命令。
我认为你的问题是表格的方法,不是张贴的。
form_for 'item', :url => {:controller => 'line_items', :action => 'update', id: item}, method: 'put'
或
= form_for :items, :url => edit_line_item_path(item) do |f|