所以這是另一個關於更新購物車數量的帖子!我能找到的任何一個似乎都已經過時,所以我很抱歉如果這看起來是重複的。購物車編輯數量
但是我在Rails 4th edition一書中關注敏捷Web開發,他們非常善良,以至於將編輯量視爲「挑戰」而不顯示答案:D。現在,當我試圖讓它工作時,我遇到了麻煩。
顯示在我的意見/車/ show.html.erb我有以下表
<table>
<tr>
<th>Quantity</th>
<th>Product Name</th>
<th>Size</th>
<th>Price</th>
</tr>
<% @cart.line_items.each do |item| %>
<tr>
<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>
<td><%= item.product.name %></td>
<td><%= item.size %></td>
<td><%= number_to_currency(item.total_price) %></td>
</tr>
<% end %>
<tr>
<td colspan="3">Total Price</td>
<td><%= number_to_currency(@cart.total_price) %></td>
</tr>
</table>
然而,當我點擊更新,我得到任何
未知的動作
行動LineItemsController找不到'29'
或
未知的動作
行動 '35' 無法找到LineItemsController
即使我完全取出id字段。我可以處理控制器端的更新功能並正確地更新它 - 我想要自己弄清楚,但我無法弄清楚可能會產生這些數字操作以及如何修復它。總之,什麼是產生這個錯誤,我該如何解決它?這可能與我在購物車視圖中有line_item表單的事實有關嗎?
不錯,繼續你的好工作:)在Ajax上實現它 – Nich