0
嘿傢伙們,我一直在試圖理解文檔並找到一個例子,但我很茫然。Form With Quantity似乎沒有提交
這只是購物車內的更新數量提交表單。但是,更新的數量沒有保存到數據庫 - 它總是使數量爲0.請幫助。
表
<% for line_item in @cart.line_items %>
<% form_for :lineitems, :url => {:controller => "line_items", :action => "cart_update", :id => "#{line_item.product_id}"} do |l| %>
<%= l.text_field :quantity, :size => '3', :value => line_item.quantity %>
<%= l.submit 'cart_update' %>
<% end %>
路線
map.connect 'line_item_update', :controller => 'line_items', :action => 'cart_update'
控制器
def cart_update
@product = Product.find(params[:id])
item = LineItem.find_or_create_by_cart_id(:cart_id => current_cart.id, :product_id => @product.id, :quantity => 0, :unit_price => @product.price)
item.quantity = (params[:quantity]).to_i
item.save
redirect_to :controller => 'products'
end
此論壇帖子可能會對您有所幫助:http://railsforum.com/viewtopic.php?id=2696 – thomasfedb 2010-06-18 15:49:15