从select_tag传递值

时间:2012-04-20 12:19:14

标签: ruby ruby-on-rails-3 ruby-on-rails-3.1

我想将选定的:ammount值传递给我的控制器:quantity。我做错了什么?

<%= 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) %>

1 个答案:

答案 0 :(得分:2)

您应该使用此处的表单将数据传递给控制器​​的操作:

<%= 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作为数量参数传递给控制器​​的操作。