2012-04-20 85 views
0

我想將選中的:ammount值傳遞給我的控制器:quantity。我做錯了什麼?傳遞來自select_tag的值

<%= label(:ammount, "Ammount:") %> 
<%= select_tag(:ammount, options_for_select([1,2,3,4,5,6,7,8,9,10])) %> 

<%= button_to 'Add to cart', line_items_path(:product_id => product.id, :quantity => :ammount) %> 

回答

2

你應該用表格這裏傳遞數據controller`s行動:

<%= form_tag line_items_path(:product_id => product.id) do %> 
    <%= label(:ammount, "Ammount:") %> 
    <%= select_tag(:ammount, options_for_select([1,2,3,4,5,6,7,8,9,10])) %> 
    <%= submit_tag 'Add to cart' %> 
<% end %> 

所有你在你的源代碼確實只是路過符號:ammount到controller`s行動量PARAM。

+0

謝謝你的回答!這個問題解決了我的問題! ;) – 2012-04-20 12:39:03